A magic trick gone awry during a birthday gathering with friends sent two joined-at-the-wrists pals to the Eagan Police Department in pursuit of the expertise that would set them free.

Newly minted 28-year-old Jeff Jabas, of New Prague, and buddy Zak Wilhelm, also 28, arrived at police headquarters Wednesday as an accidental tandem and admitted to “celebrating with some adult beverages and trying to show off with the new handcuffs,” said police officer Aaron Machtemes. “Halfway through the trick, they realized they lost the key.”

After they turned in vain to YouTube videos for a solution, the mother of Jabas’ girlfriend said that “even though it’s going to be embarrassing, they need to go to the police for help,” Machtemes said.

Jabas said he and Wilhelm spent about 2½ hours locked together, much to the amusement of their girlfriends. Bobby pins and safety pins were of no use.

“I had a grinder out in my truck,” Jabas said. “If worse came to worst, I was cutting them off.”

So they got a sober celebrant to drive from Wilhelm’s house in Eagan to the police station, where “we exchanged some jokes and then set them free” from the ankle handcuffs, said Machtemes, who held and turned the key to their freedom.

Machtemes said he told the pair, “ ‘This is social media gold. Mind if I put it on our Twitter?’ They agreed and posed for the photo.”

Jabas seemed as sheepish about the Twitter photo as he did about his predicament, saying, “I looked high, but Zak was the only one drinking. I said [to police], ‘You guys could have taken a better picture.’ ”

Machtemes said that in his 11 years in uniform, “I’ve never had to free someone who arrested themselves. ... I’m sure it happens more than we know.”