Troublemaking actor Shia LaBeouf went berserk in the audience at the Broadway musical “Cabaret” Thurs­day night and was hauled off in handcuffs to a station house — where he told cops, “I’ll f–k you up,” called an officer a “f-g,” and was muzzled with a face mask for spitting, sources said.

The “Nymphomaniac” star was slapping people on the behind and in the back of the head while smoking at around 9:30 p.m. in the Studio 54 theater, according to law-enforcement sources.

When cops approached him, he was “incoherent” and “very agitated,” they said.

http://instagram.com/p/punIAToQYV/?modal=true

He tried to quickly walk away from officers but fell flat on his face, the sources said.

Police hauled him out, his hands cuffed behind him, as theatergoers looked on.

At the Midtown-North station house, he allegedly became belligerent, demanding the cuffs be removed.

“F–k you. I’ll f–k you up!” the 28-year-old LaBeouf said, according to the sources.

Cops decided to not take the cuffs off the agitated “Transformers” star, and he allegedly started spitting, prompting officers to put a face mask on him.

LaBeouf then unloaded on the arresting officer and used a ­homophobic slur.

“I have millions and millions of dollars and attorneys,” the ­unhinged actor said. “I’m going to ruin your career,” he added, then allegedly called the cop a “f-g.”

A spit mask like the one cops used to muzzle LaBeoufSteven Hirsch

One police source said the actor smelled terrible and lied about ­being in the Army.

He was charged with criminal trespass, harassment and disorderly conduct, according to the sources.

“Just saw Shia LaBeouf in handcuffs in tears surrounded by 6 police officers outside of CABARET the musical,” tweeted Benj Pasek.

The actor has had his share of bizarre incidents in the past.

In January, he was videotaped head-butting a man during a bar brawl in London, according to ABC.

In February, he was seen disheveled, with a paper bag over his head, at the Berlin Film Festival.

He was arrested at a Chicago Walgreens in 2007 for refusing to leave the store.

After Thursday night’s bust, one “Cabaret” actor reportedly joked about it on social media.

“Ladies and gentlemen, this is your places call for Act II. Also, to let you know, Shia LaBeouf has just been escorted from the building in handcuffs. Yep, that just happened,” cast member Danny Burstein wrote on Facebook, according to the website Just Jared.