A White House speechwriter resigned on Friday after his former wife claimed that he was violent and emotionally abusive during their turbulent two-and-a-half-year marriage — allegations that he vehemently denied, saying she was the one who victimized him.

The abrupt departure of David Sorensen, a speechwriter who worked closely with senior policy adviser Stephen Miller, came as The Washington Post was preparing a story about abuse claims by his ex-wife, Jessica Corbett. Corbett told The Post that she reported his behavior to the FBI last fall as the bureau was conducting a background check of Sorensen.

White House officials said they learned of the accusations by Sorensen’s wife on Thursday night, before The Post’s inquiries.

“We immediately confronted the staffer, he denied the allegations and he resigned today,” spokesperson Raj Shah said in a statement on Friday evening.

In a text message to The Post, Sorensen said he stepped down because he “didn’t want the White House to have to deal with this distraction.”

“It should be able to focus on continuing President (Donald) Trump’s historic accomplishments for the American People,” he texted.

Sorensen’s resignation comes two days after another administration official, staff secretary Rob Porter, departed after two ex-wives said that he physically abused them. Senior White House officials and the FBI knew about the allegations for months, raising questions about why he was allowed to remain in his post.

Administration officials said Sorensen’s position as a speechwriter at the Council on Environmental Quality, a division of the Executive Office of the President, did not require a security clearance. His background check was ongoing, they said. The FBI declined requests for comment.

Corbett first contacted The Post a week before Porter’s case became public. She said that during her marriage to Sorensen, he ran a car over her foot, put out a cigarette on her hand, threw her into a wall and grasped her menacingly by her hair while they were alone on their boat in remote waters off Maine’s coast, an incident she said left her fearing for her life. During part of their marriage, he was a top policy adviser to Republican Maine Gov. Paul LePage.

She said she did not report her abuse allegations to police because of Sorenson’s connections to law enforcement officials.

Corbett said several of the incidents involved alcohol and acknowledged that she slapped Sorensen a number of times after he called her a vulgar term.

Two friends and associates of Corbett said she confided in them during the marriage that her husband was abusive. Corbett also provided records of text messages and emails in which Sorensen berated her with vulgar language and she discussed the deteriorating marriage with others. She gave The Post a photo of her hand bearing a scar she said was from the cigarette burn.

In a lengthy statement, Sorensen said he had “never committed violence of any kind against any woman in my entire life.”

“In fact, I was the victim of repeated physical violence during our marriage, not her,” he added, saying he had consulted with an attorney and was “considering legal options to address her defamation.”

Sorensen alleged that Corbett punched him on multiple occasions. After one such episode, he said, he attempted to leave in his car and she ran after him as he was pulling away, injuring herself in the process.

In another incident, he said, she grabbed the steering wheel as he drove on a highway and punched him in the face during an argument.

Sorensen provided photos of what he said were injuries his ex-wife inflicted upon him during their fights, including bruises and scrapes.

He said that while he had hoped never to have to discuss his ex-wife and their tumultuous marriage, “this incident is an opportunity to highlight the grossly underreported and unacknowledged issue of female-on-male domestic violence.”

In response to Sorensen’s allegations on Friday evening, Corbett maintained that her violence never escalated beyond slapping him. “Everything I told you is 100 percent true and that is why he had to resign today,” she said.

The couple’s uncontested divorce became final in September, according to records reviewed by The Post.

Corbett said she detailed her abuse allegations to an FBI agent who came to her home to interview her on Oct. 5, 2017, as part of Sorensen’s background check process.

A Maine Republican operative, who spoke on the condition of anonymity out of fear of political retribution, said he talked to Corbett shortly before her meeting with the FBI that day.

“She told me she was a little nervous about what to tell them,” he said. “She told me later that she told them the truth.”

In one of several interviews with The Post, Corbett called it “scary” that someone like her ex-husband had access to sensitive information at the White House after what she told the FBI.

“Everyone can think you’re the most wonderful guy, but you’re throwing women into walls by night,” she said.

For his part, Sorensen said that “like many domestic abusers, she was especially adept at controlling her rage so that no others witnessed her physical attacks.”

During their marriage, Corbett and Sorensen were a well-known couple in Maine Republican politics.

Corbett said she worked for Sen. Marco Rubio, R-Fla., in his first Senate bid and on former House speaker Newt Gingrich’s 2012 campaign before becoming finance director for Rep. Bruce Poliquin’s, R-Maine, successful 2014 House bid. Sorensen is a former spokesman for Maine House Republicans and the state party and was a spokesman for Maine’s Department of Health and Human Services.