Man arrested for trying to rob the coffee cart outside Police Headquarters. (Seated with cops) pic.twitter.com/ej6QGdpBKF — jdavidgoodman (@jdavidgoodman) August 5, 2014

A dim-witted thief picked the worst place to rob someone — right in front of police headquarters.

The 24-year-old suspect tried to run off with the tip jar on a coffee cart outside 1 Police Place in downtown Manhattan on Tuesday morning but was nabbed by a fast-as-lightning worker and a loyal cart customer — an NYPD detective.

“How stupid can you be to do that when the sign right here says police headquarters?” a police source told The Post.

Zikri Hodza, the nephew of the cart’s owner, had been manning the stand — which serves up breakfast to dozens of cops heading to work daily — when the incident occurred around 10:30 a.m.

Hodza was busy trading cash for caffeine with customers when Jean Morillo, who had been panhandling nearby, grabbed the tip jar, authorities said.

“I heard something, and I looked up, and he was running away with the tip jar,” said Hodza, 24.

Hodza chose the perfect day to wear a “Flash” T-shirt — he quickly channeled the comic-book character known for his speed and went after the thief. He was backed up by one of the cart’s customers, an NYPD detective named Larry.

“Larry stopped him from running away,” Hodza said. “He grabbed him, and the money went flying everywhere.”

But the thief didn’t go down without a fight, flipping around and taking his shirt off before police cuffed him and sat the thwarted thief on a nearby bench to wait to be taken away.

Nearby patrons, including a few cops, collected the cash — $26.25 in total — strewn across Police Plaza during the scuffle and gave it back to Hodza.

Cart owner John Quader, who has been serving up morning joe at that location for 18 years, said 80 percent of his customers are cops.

Morillo was charged with assault on a police officer, petit larceny and resisting arrest. The officer reportedly suffered pain to his left hip and elbow, but refused medical attention.