North Dakota Democrat Sen. Heidi Heitkamp went out on limb three years ago to convince skeptical members of her party to support legislation that lifted 40-year ban on exporting crude oil from the United States to countries around the world.

Now, as she battles to keep her seat this November in a state that voted overwhelming for President Donald Trump in 2016, she's hitting back against her challenger, Rep. Kevin Cramer, R-N.D., for running an ad claiming credit for a cornerstone of her re-election campaign.

Both lawmakers agree that the 2015 bill repealing the ban, which had been in place since an Middle Eastern oil embargo led to an oil shortage crisis in the 1970s, has been a boon for North Dakota, a state with significant oil reserves that have buoyed its economy in recent years. But Heitkamp, considered one of the more vulnerable Senate Democrats, said Cramer's claims of leadership in getting the legislation passed are misleading.

"This was not a place where you would have seen Congressman Cramer with his sleeves rolled up, in the depths of making this happen," Heitkamp told NBC News in an interview on Thursday. "I think that it represents a pattern of sitting back… and then making sure you're in the shot. Making sure you're in the ribbon cutting."

In the campaign ad that ran this month, Cramer said he "helped lead the repeal" of the ban on foreign exports.

"I helped lead the repeal of the oil export ban," Cramer tells the camera in the ad. "Now, foreign markets are open so North Dakota can deliver energy to the world."

Who deserves what credit here? Let's take a look at the facts.

What's the basis for Cramer's claim?

Cramer started working on behalf of a repeal in late 2014, co-sponsoring one early attempt at a repeal in December 2014. He told NBC News he started meeting with stakeholders, giving floor speeches, and co-sponsoring more pieces of legislation aimed at ending the ban on oil experts.

"My main role in getting it across the finish line was getting Democratic co-sponsors," the congressman told NBC News. "It was a long year organizing meeting after meeting after meeting."

Cramer was a co-sponsor on a bill to repeal the ban, H.R. 702. It passed the House on a 261-159 vote in October 2015, with 137 cosponsors, 16 of them Democrats.

Retiring Rep. Joe Barton, R-Texas, wrote that bill. Asked who the key players were, he listed Rep. Henry Cuellar, D-Texas, and five top Republicans before Cramer.

Still, he said Cramer can fairly claim some credit for the law.

“He was there early and he actually showed up when we needed things to get done,” Barton told NBC News on Wednesday, specifically crediting Cramer for coalescing support among junior members and the business community.

But President Barack Obama's White House threatened to veto Barton's bill, which also faced considerable hurdles in the Senate, where the Democratic caucus broadly opposed the legislation as a handout to oil companies that would hurt the environment. The repeal effort might have ended there, if not for Heitkamp.

Why Heitkamp touts the repeal as a signature achievement

Heitkamp, who was narrowly elected in 2012, first called for the repeal of the ban on crude oil experts in August 2014. She wrote a standalone repeal bill and began trying to sell the issue to her fellow Democrats throughout 2015, pitching it as an economic boon and a source of good jobs while lobbying the White House on the issue.

She worked with Sen. Lisa Murkowski, R-Alaska, to push the issue, and started putting the oil industry in the same room with unlikely supporters like Sen. Cory Booker, D-N.J., and Sen. Brian Schatz, D-Hawaii, to talk a repeal out.

Heitkamp was "just dogged in her efforts to help educate her party," Murkowski told Bloomberg after the repeal.

Still, Heitkamp told NBC News on Thursday, it became clear that standalone legislation wasn't going to make it out of the Senate or past the White House.

"This needed to be part of a broader package," she said.

She began working with Sen. Martin Heinrich, D-N.M., in September 2015 to pair it with renewable energy investments that could get her party — and notably the solar-energy loving Sen. Harry Reid, then the minority leader — on board. She paired renewable energy investments, including a five-year extension of wind and solar tax credits, with the repeal and Democratic support grew.

Legislation to repeal the ban was placed, along with those tax cuts, into the omnibus spending bill that went on to pass both the House and Senate.

"At the end of the year, when the deals were getting cut, and these two ideas were married, that's basically how we got it across the finish line," Heitkamp said.

So, who should get more credit?

Barton on Wednesday was eager to share his bill's success with Cramer. "When you’re successful, there’s plenty of credit to go around," he said.

Cramer, for his part, called Heitkamp "insecure," "anxious," and "immature" for disputing his role in the repealing the ban, and suggested pressure from House Speaker Paul Ryan, R-Wisc., was what helped override the White House threat of a veto.

“I’ve never had a big beef with her taking credit for it. I’m perplexed with her anxiety on my role of it,” he told NBC News Thursday. “I honest to God think she sometimes thinks she’s the only person who had anything to do it.”

Later in the day, Cramer, speaking on a local radio show, downplayed Heitkamp's role, saying the House "got the ball 99 yards down to the one-yard line. They walk it in and she spikes it." He suggested her criticism of him was a "hissy fit."

But Barton in 2015, days after the bill was passed, told Bloomberg that he didn't know if the law would have passed without Heitkamp.

Heinrich, the democratic senator from New Mexico who worked with Heitkamp to pair tax credits with the repeal, said Heitkamp was "absolutely central" to the deal and that there was “not a chance” the bill would have gotten through the Senate without those credits.

“Democratic caucus would have been overwhelmingly against. It takes 60 to Tango in the Senate,” he told NBC News in a statement.

Sen. Sheldon Whitehouse, D-R.I., who speaks weekly on the Senate floor about climate change, said Heitkamp was "key to getting that deal done."

"She went into our caucus and managed to balance the demands of progressives like me, who want to reduce carbon emissions and protect our oceans, with the demands of proponents of rolling back the ban," he said in a statement to NBC News.

Cramer's ad is technically accurate — he did "help to lead" the effort to repeal the ban in the House — but the credit he can claim stops there. In defending himself on the radio program, he overstated how much he did.

Heitkamp turned "no" votes into "yes" votes in the Senate, and by many accounts, was crucial to getting the bill across the finish line and signed by the White House.

Asked if she was "insecure" about Cramer, as he claimed, Heitkamp laughed.

"I’m not insecure, but I do think people should tell the truth about what actually happens and how these measures get passed," she said.