U.S. Rep. Dan Donovan has been accused of using his official position to get his baby mama’s son out of a heroin arrest on Staten Island in New York City.

Donovan, a former district attorney who now represents Staten Island and part of South Brooklyn, stepped in after his domestic partner’s son was arrested with a friend for “criminal sale and possession of a controlled substance (heroin),” according to an allegation filed with the Office of Congressional Ethics last week.

Timothy O’Connell, son of Serena Stonick, was detained with the female friend after the bust, the allegation states. The friend’s name is being withheld by The Post.

“Later that evening, Donovan, while serving in Congress and as a former District Attorney, visited the 122 Precinct and used his position to illegally request that officers issue O’Connell and [the friend] a ‘desk appearance ticket’ instead of proceeding with normal arrest protocols,” the allegation says. “This intervention allowed the detained to be immediately released from custody, as well as the records to be sealed.”

A desk appearance ticket lets an arrested person show up in court at a later date to answer a summons and avoid being sent to central booking, jailed or arraigned.

While one NYPD source said DATs are possible in heroin cases if the amount of the drug is small and the suspect has no prior arrests, another expert said such tickets are rare in heroin busts.

“DATs are reserved for minor offenses — smoking marijuana in public or jumping a turnstile,” said Joseph Giacalone, a retired NYPD detective and professor at John Jay College of Criminal Justice. “But heroin? Absolutely not. Especially with the opioid crisis going on.”

Police confirmed O’Connell and the woman, both 19 at the time, were arrested on Dec. 3, 2015, in the 122nd Precinct, but no other information was available because the cases were sealed.

Donovan denied the charge and characterized it as a political hit.

“Like many families, Dan has been dealing with a loved one’s opioid addiction — in private until now. These allegations are not only 100 percent false, but Dan has a long history of recusing himself from matters involving close friends and family,” said Donovan spokesman Pat Ryan.

“Neither Dan nor anybody at his direction or suggestion or wink or nod in any way, shape or form, intervened, interfered, inserted themselves in any way into this judicial process,” Ryan added.

Ryan noted that when Donovan first began dating Stonick in 2011, she told him that her daughter also struggled with addiction and was in drug-treatment court. As the DA at the time, Donovan requested and was granted a special prosecutor in that case.

Donovan and Stonick now have a young daughter together.

“This is a disgusting, vicious and false attack on a young man’s struggle with addiction to score political points two months before an election,” Ryan said, referring to June’s GOP congressional primary in which Donovan will face ex-con former Rep. Michael Grimm.

Ryan pointed to O’Connell’s arrest report, which shows the young man did not make a phone call after being collared.

O’Connell’s attorney, Joe Mure, said his client was charged with seventh-degree criminal drug possession, not sale. The misdemeanor is punishable by up to a year in jail. The charge was dismissed in March 2016.

Mure claimed four glassine bags of heroin were found in the woman’s wallet when police pulled her and O’Connell over and that marijuana was later found in her shoe at the station house. But the arrest report indicates O’Connell was seen buying heroin.

Ryan said, “We’re not saying [O’Connell] was charged without any cause.”

O’Connell denied doing drugs.

“No marijuana, no heroin. I don’t even drink . . . I go to church every Sunday,” he said.

He denied Donovan helped him get out of trouble. His friend would not comment on the case.

The tipster who made the allegation to the Office of Congressional Ethics said “multiple sources” contributed to the account, including a retired cop and an active detective on Staten Island, elected officials and someone close to the female friend.

The source close to the friend said the woman was driving O’Connell when he asked to go to a house in Great Kills. The source was told that “he went in, he came out. They continued driving. They were pulled over. They were found with drugs.”

The source said that if Donovan did quash the arrests, he made the wrong decision.

“I thought if these kids went through the system and you get a taste of prison . . . That’s going to scare you some, and maybe it was a chance to keep these kids off drugs,” the person said.

Citing confidentiality rules, the ethics office would not comment on the allegation.

Additional reporting by Shawn Cohen and Dean Balsamini