President Trump is aggressively campaigning for Republican Senate candidates around the country and belittling their Democratic ­rivals, with one notable exception — Sen. Heidi Heitkamp of North Dakota.

Trump’s affinity for Heitkamp, who got a shout-out and a handshake at a recent White House bill signing, has frustrated top Republicans who see winning her Democratic seat as crucial to holding onto their fragile 51-to-49 majority. No one has felt it more acutely than GOP Rep. Kevin Cramer, whom Trump personally recruited to run against Heitkamp.

Upset, Cramer contacted White House Chief of Staff John F. Kelly to appeal for political help and traded warning shots with Trump’s legislative affairs director, Marc Short.

Cramer says he believes Trump is giving Heitkamp preferential treatment because she is a woman. He accused the first-term senator of being insecure and going out of her way to stand near Trump at last month’s signing of the banking bill, which Cramer also attended.

“Have you ever watched the video? It’s obscene,” said Cramer, who in an interview with The Washington Post re-created Heitkamp’s movements and the setup of the room.

The tension between the White House and Cramer could have implications for GOP control of the Senate in November’s midterm elections and has exposed friction within the White House, pitting the legislative operation intent on securing the support of centrist Democrats against a ­political team determined to oust them.

The contest also has become a deeply personal test of both candidates’ relationship with the president, who won North Dakota by nearly 36 points in 2016. Trump had considered Heitkamp for a Cabinet post and even tried to persuade her to switch parties. This year, the president worked furiously to get Cramer to run after he initially declined. The congressman is expected to win the North Dakota Republican primary on Tuesday.

Cramer’s unusual chat with Kelly occurred June 1, two days after he had disparaged Short in a local radio interview, largely blaming him for the way the White House had treated him and questioning Short’s abilities.

“If Marc Short was very good at his job, you know, we’d have a repeal and replacement of Obamacare,” Cramer said in a surprising display of animosity toward a White House official.

This upset Short, who quickly brought the interview to the attention of the National Republican Senatorial Committee.

Cramer later called his radio comments a “little shot across the bow” that got the White House’s attention. His words also drew some blunt advice.

“There’s no doubt that Congressman Cramer has been a more reliable supporter of the administration,” said Short, comparing him with Heitkamp. But he added, “I think he’s better spending his time focused on his opponent than on a White House staffer who has zero percent name ID in North Dakota. But that’s up to him.”

The behind-the-scenes discussions were described by several people with knowledge of private conversations. A White House spokesman did not respond to a request for comment.

Trump has made campaign stops in Indiana, Missouri and Tennessee in recent months, but he has not campaigned in North Dakota and has steered clear of mocking Heitkamp the way he has with other Democrats.

“Heidi, thank you very much, appreciate it,” Trump told her last month when he signed the bill to ease restrictions on banks. Heitkamp co-sponsored the measure.

Heitkamp was the only Democratic lawmaker at the May 24 White House event. She was invited by Short. She stood directly to Trump’s left; Cramer was behind the president.

“I was standing by the door when people came in and, you know, you kind of fill in from the front to the back,” Heitkamp said.

“I do think there’s a little difference in that she’s a woman,” Cramer said. “That’s probably part of it — that she’s a, you know, a female. He doesn’t want to be that aggressive, maybe. I don’t know.”

Short offered an even more pointed response. “Remind me who the president ran against for the presidency,” he said, referring to Hillary Clinton.

While White House officials are trying to project unity as the midterms draw near, there is some disagreement about balancing legislative priorities — which often means working with Democrats, given the GOP’s slim majority — with winning Senate races. Some argue the campaign is paramount.

“The power of this office and the power of this building is immense, and if you are not maximizing that, then what are you doing?” said one White House official, who, like others interviewed, spoke on the condition of anonymity to be candid.

While Cramer’s relationship with Short has been rocky, he has formed a close bond with Bill Stepien, the White House political director. He says they talk and text regularly.

Cramer and Short spoke privately last week, a conversation they said improved their relationship. Heitkamp’s relationship with Short has appeared cordial, even friendly at times.

“Marc’s job is to coax the people that you can’t count on, that aren’t reliable,” Cramer said. “And sometimes the rest of us get taken for granted.”

Short said he tries to be straightforward with every member of Congress.

The key to reelection for Heitkamp and the other nine Democratic senators running in states Trump won in 2016 is convincing voters they are bipartisan to win crossover votes without alienating the Democratic base.

Heitkamp is one of just seven Democrats who voted to confirm Trump’s pick of Mike Pompeo for secretary of state and one of the six who voted for Gina Haspel to be CIA director. Cramer said Short’s team asked him to make supportive statements about the nominees to pressure Heitkamp to back them. This month, Americans for Prosperity, a group linked to conservative billionaires Charles and David Koch, announced a digital ad campaign thanking Heitkamp for her support for the banking bill.

But Heitkamp disagrees strongly with Trump’s approach to tariffs and voted against the sweeping GOP tax bill. She is trying to contrast herself with Cramer by branding him a “rubber stamp” for Trump. “I have not been a rubber stamp for either political party,” she said.

Heitkamp plans to release a new television ad on Tuesday emphasizing this theme. "I only answer to you," says Heitkamp in her closing line of the commercial.

Cramer is dismissive of Heitkamp’s policy straddle.

“She’s trying to be like Kevin, except I get to be Kevin,” said Cramer, who highlighted his support for the tax bill, which Trump signed into law.

As North Dakota’s lone representative, Cramer has triumphed statewide three times, making him well-positioned to oust Heitkamp.

She and the other vulnerable Democrats running for reelection in states Trump won have become friendly as they confront similar obstacles.

“Hey there, sweetcakes!” Heitkamp cheerfully greeted Sen. Joe Donnelly (D-Ind.) when he popped into an interview she was doing earlier this year at the Democratic Senatorial Campaign Committee headquarters.

“We’re the dishwashers of this operation,” Donnelly joked about himself and Heitkamp.

In May, Trump held a rally in Indiana, where he called Donnelly “Sleepin’ Joe” and touted his GOP challenger, Mike Braun. He has not come up with a nickname for Heitkamp.

For Cramer, the wait for Trump to campaign with him continues.

“It’d be fun to have him out. And I expect he’ll come to North Dakota,” Cramer said. “He promised me he would.”