A bitter surprise was in store for this butter-fingered crook.

Security footage obtained by The Post on Sunday shows a man stumbling into a Coney Island Dunkin’ Donuts and Baskin-Robbins and dropping a gun — right in front of a trio of NYPD officers who just happened to be in the fast food restaurant.

The bumbling perp, identified by sources as 34-year-old Emmanuel Lovett, seems to be adjusting his pants as he strolls into the donut shop on Saturday at around 11:30 p.m. — and doesn’t appear to notice the loaded weapon falling to the ground.

A pair of cops can be seen rushing toward the unlucky ex-con and putting him in handcuffs, while the third picks up the gun.

“3 of our cops are in the local Dunkin/Baskin Robbins. A fella walks in, adjusts his pants & out drops a loaded gun on the floor,” tweeted NYPD Transit Chief Edward Delatorre.

“Now the repeat felon carrying it is in custody, all because a Transit cop had a craving for cake batter ice cream🍦 (seriously, this actually happened).”

Lovett was charged with felony criminal possession of a loaded firearm, among other charges and was expected to be arraigned in Kings County Criminal Court Sunday.

Records show he’s previously been arrested for robbery and criminal possession of marijuana.

Additional reporting by Tamar Lapin