As the U.S. and other world powers closed in on a preliminary nuclear deal with Iran last month, a few senators were invited to a White House Situation Room briefing for a progress report.
"You're telling us we have to choose between loyalty to the president and loyalty to our constitutional role?" Sen. Chris Coons (D-Del.) said he told administration officials. "That's not a good place to put us. So what's your Plan B?"
The answer, Coons recalled, was firm but disappointing: There would be no negotiation, and the president would veto a proposed bill empowering Congress to approve the Iran deal.
But by this week, as momentum was building in favor of the legislation, Obama's top aide came to the Capitol to tell senators of a change of heart. The president was prepared to sign the bill.
The reversal followed more than two weeks of intense debate between the White House and lawmakers over how much congressional involvement would be allowed on the deal. The discussions ultimately produced what Obama on Friday called a "reasonable compromise" that protected, in his view, the presidential prerogative to conduct foreign policy.
Obama's reluctant acceptance of Congress' role in an Iran deal was a shift from his approach to governing in recent months. He has enjoyed success by taking executive action, rather than pushing for legislation, on such policy matters as climate change and immigration.
The standoff on Iran showed the limits of that strategy, and the extent to which even Obama's traditional allies on Capitol Hill were unwilling to let him go it alone in pursuing a deal with a Middle Eastern power that has been historically hostile to the U.S.
"He has the best of intentions," said Democratic Sen. Tim Kaine of Virginia, one of the first politicians outside Illinois to endorse Obama's 2008 candidacy and a lead sponsor of the bill. "But this is big and complicated."
Negotiators from Iran and six countries, including the U.S., began discussing a deal in earnest two years ago to limit Tehran's nuclear program in exchange for easing sanctions that have crippled the nation's economy.
After diplomats announced a broad framework agreement April 2, Obama wasted no time trying to blunt expected criticism.
Speaking in the Rose Garden that afternoon, the president said the public broadly supported his quest for a diplomatic solution by the June deadline for a final agreement and warned of the consequences should lawmakers "kill this deal."
But it quickly became apparent that support was building to give Congress the power to approve a final deal, despite Obama's caution. Senate Democrats who had helped delay the bill and another were reluctant to heed additional requests for time.
Obama found himself stuck with a playbook that appeared to have stopped working while a legacy-defining foreign policy achievement lay just out of reach.
Seeking a solution, the White House began looking for ways to advance alternative legislation to line up support from Democrats who wanted congressional review. The president and other White House officials made more than 130 phone calls to members of Congress in the weeks after the framework deal.
But none of them was as important as those to a new partner who emerged at a key moment: Sen. Benjamin L. Cardin of Maryland, who took over as the top Democrat on the Foreign Relations Committee as international negotiators reached the preliminary agreement with Iran.
In an interview, Cardin said that after he took over the committee seat, the president and other officials were still pressing for a delay in legislation until after the June 30 deadline to reach a final agreement with Iran. They feared congressional involvement would jeopardize further progress in the nuclear talks.
"But it evolved into allowing me to negotiate," Cardin said. "They gave me the confidence that if I could reach a certain plateau, their position on the deal might change."
Cardin acted as an intermediary between the White House and committee Chairman Bob Corker of Tennessee, a Republican who sponsored the bill giving Congress a say over whether to agree to a deal with Iran, as well as with Democrats such as Coons and Kaine who supported Corker's bill.
"I felt very confident a couple days before we voted that we were going to reach an agreement, and confident that the White House would back off," Cardin said.
The typically even-tempered Obama revealed his distress over congressional back-seat driving, telling reporters as recently as Saturday that he couldn't understand why "everybody is working so hard to anticipate failure."
But by the time Secretary of State John F. Kerry, along with Energy Secretary Ernest J. Moniz and others, were sent to the Capitol to brief lawmakers on the preliminary agreement, Corker and Cardin were finalizing their compromise.
They ultimately garnered support from members of the Foreign Relations Committee, and just an hour before the panel was to formally consider the bill, White House Chief of Staff Denis McDonough told Cardin that the White House supported the new language.
Obama said Friday that the bill "allows me to interpret the legislation in such a way that it is not sending a signal to future presidents that each and every time they're negotiating a political agreement, that they have to get a congressional authorization."
The next test for Obama's goal of reaching a deal with Iran is whether the bill can survive challenges when it reaches the full Senate, as early as next week, and then the House. Corker, Cardin and others have said they would resist amendments that might renew a veto showdown.
"If that happens, I think you'll see the Democrats coalesce behind the president," Cardin said. "I don't think the president has to do a lot of lobbying for us to stay united on this."