On Wednesday morning, Paul Ryan, the Speaker of the House, stepped before cameras on the Hill and spoke about the fraught negotiations on debt and spending that will consume Washington through the end of the year. Congress was facing September deadlines for both the federal government’s ability to borrow money and the funding of the government. Raising the debt ceiling would require Democratic votes in the Senate, and likely in the House, too. A reporter asked Ryan about a proposal from senior Democrats in Congress, for a deal to raise the debt ceiling for three months. “I think that’s a ridiculous idea,” he said. “I hope that they don’t mean that.”

For weeks, Chuck Schumer, the Senate Minority Leader, had been plotting a strategy to use the debt-ceiling vote to extract concessions from Donald Trump and his fellow-Republicans. Over the weekend, the White House and Senate Republicans indicated that they wanted a debt-ceiling increase attached to a bill to provide immediate aid for areas of Texas and Louisiana affected by Hurricane Harvey. The plan was perfect for the G.O.P. The House would pass a “clean” debt ceiling that most Republicans would probably support. In the Senate, Mitch McConnell, the Majority Leader, would add the Harvey money and pass the two bills together with the help of Democrats. The plan was to raise the debt ceiling for eighteen months, which would kick the next difficult vote past the 2018 midterm elections. In the House, such a bill likely would have lost some votes from both parties, but, given the urgency of the hurricane aid, it was a decent bet to pass. Best of all, for G.O.P. leaders, the bill would have taken away the Democrats’ debt-ceiling leverage from the coming debates on immigration, government spending, and health care.

But, when conservative Republicans came out vocally against McConnell and Ryan’s plan, Schumer and Nancy Pelosi, the top Democrat in the House, saw an opening. They called for the three-month debt-ceiling deal, which would kick the issue into mid-December, allowing them to maintain their leverage as Congress worked out agreements on other agenda items.

At his morning press conference, Ryan had been withering about this idea. “Let’s just think about this,” he said. “We’ve got all this devastation in Texas. We’ve got another unprecedented hurricane about to hit Florida. And they want to play politics with the debt ceiling? That will strand the aid that we need to bring to these victims of these storms that have occurred or are about to occur. And then they also want to threaten default on our debt? I think that’s ridiculous and disgraceful that they want to play politics with the debt ceiling at this moment.”

He added that the idea was “unworkable,” and, speaking for Trump, noted, “What the President doesn’t want to do is to give more leverage where it shouldn’t occur on the debt ceiling.”

An hour later, in the Oval Office, Ryan, McConnell, Schumer, and Pelosi sat down with Trump and Steve Mnuchin, the Treasury Secretary, to negotiate. The Republican leaders—at first—stuck to their demand for an eighteen-month debt-ceiling increase. But the Democrats held fast as the Republicans dropped their request to twelve months and then to six months. Mnuchin argued that the financial markets needed a long-term deal. Trump cut him off and abruptly sided with Schumer and Pelosi on their three-month request.

After the deal was announced, Republicans inside and outside of government were shocked. Ryan was left looking ridiculous. “Trump’s made a career out of being a gut player,” a Republican close to McConnell told me. “The problem is, his gut is always wrong when it comes to advancing a legislative agenda.” Yet, aboard Air Force One, Trump seemed pleased with the deal. “We had a very good meeting with Nancy Pelosi and Chuck Schumer,” Trump said. “We agreed to a three-month extension on debt ceiling, which they consider to be sacred.” When I called around to Democratic offices on Wednesday afternoon, several aides were careful not to gloat about what they had accomplished, lest Trump realize how much he had given away to “Chuck and Nancy,” as Trump called the Democratic leaders several times in his gaggle with reporters.

Later in the day, the White House began arguing that the deal was actually a win for Trump, because it kicked several difficult issues from September to December and allowed Trump to focus solely on tax reform this month. Perhaps. But McConnell and Ryan were plotting to take away a loaded weapon from Schumer and Pelosi, and Trump returned it to their hands.