NEIL PATRICK HARRIS has been slapped with a stinging “marriage ulti­matum” by his longtime fiance David Burtka – “Marry me or set me free!”

Sources say David, 38, has been hot to tie the knot since the “How I Met Your Mother” star, 40, started his starring stint as a transgender rock diva in the Broadway musi­cal, “Hedwig and the Angry Inch.”

“Neil’s play is the hottest thing on Broadway right now,” a source told The ENQUIRER.

“He shed 20 pounds for the role and strips down to his shorts on stage. Gay men are throwing themselves at him, and it’s driving David nuts!”

An insider added: “David has given Neil a marriage ultimatum – ‘marry me or set me free!’ He’s beside himself with worry that he’ll lose Neil if they don’t wed.”

The former “Doogie Howser, M.D.” star and David – who worked as an E! Network cor­respondent thanks to Neil’s connections – have been together  since 2004, and have 3-year-old twins, Gideon and Harper.

Emmy winner Neil announced their engagement after the Mar­riage Equality Act was passed in New York in June 2011.

But as The ENQUIRER reported in March 2013, Neil abruptly canceled wedding plans after they had a huge blowup that was sparked by David accusing Neil of using him as “arm candy” at Hollywood award shows.

A rep for the actor said the idea of a marriage ultimatum was “laugh­able,” and Neil has called marriage to David “inevitable.” Still, the source said friends aren’t so sure and fear there could be a vicious custody battle over the twins if they ever split.

“Neil is telling David that when the time is right they will wed,” said the source. “But David says they’ve been waiting too long. Still, David jumps at the chance to be seen with Neil. At the opening night party for Neil’s play, he put on a pink suit and mugged for photographers.

“But David won’t rest until he and Neil make their union official.”