WASHINGTON — When Nancy Pelosi chided President Donald Trump in the Oval Office that he didn't have the votes in the House to pass a government funding bill that included $5 billion for his border wall, she was probably expecting that Trump's GOP critics, particularly those on their way out the door, would buck him.

But when House Republican leadership, backed into a corner by the White House and the Freedom Caucus, brought it to the floor Thursday night, all but eight Republicans voted in favor of a temporary spending bill that would avert a shutdown and provide Trump's wall money. That, coupled with the 20 House Democrats who weren't there to vote, handed Trump a victory, at least optically, and made Pelosi's assessment incorrect.

GOP House Majority Whip Steve Scalise, R-La., crowed about Pelosi's misjudgment and said proving her wrong gives "the president a lot more leverage."

Several of the Republicans who voted yes are among those who have critiqued Trump's handling of this shutdown fight and have openly supported the House taking up the clean spending bill that passed in the Senate. Many are those who lost their re-election because of voter repudiation of Trump.

U.s. Rep. Ryan Costello, R-Pa., a moderate who decided not to run for re-election over his frustrations with the direction of the party under Trump, has been a fixture on cable news of late admonishing Trump and the far right who the president seeks to appease. And yet, Costello supported the bill.

On Friday, Costello said he would have preferred a clean bill, but that he saw his vote not as siding with Trump but simply as a way to keep the government open.

"I was not going to use my vote as a form of protest, but I'll give my opinion on how I think he handled it which is very poorly, which has shown weakness," he said. "It's ham-handed."

Costello said if he'd voted against the bill, then people could have rightly accused him of voting to shut down the government.

But Democrats see it quite differently. By not bringing up the Senate's clean spending bill, the House GOP invited a shutdown and bowed to Trump's threats.

"I can certainly see that, but if I start voting because of the perception of who it empowers or who it doesn't, you will ultimately just be voting for things based on whether it makes people look good or bad," Costello said. "The question was, 'will I now vote to shut down the government on the account of the fact that there was $5 billion of border wall funding?' "

Other House Republicans cited the same reasoning. Brian Fitzpatrick, R-Pa., who won his re-election distancing himself not only from Trump but the Republican Party as a whole, voted for the bill solely to keep the government funded, according to his spokesman. And Mike Coffman, R-Colo., who lost his re-election, tweeted: "I supported the House-passed $5.7 billion funding-level for border security as a starting point for negotiating with the Senate and the president. My hope is that a compromise will be reached that will avoid a shutdown," he wrote.

Mark Sanford, R-S.C., who has not been shy with his denouncements of Trump and lost his re-election in part because of his rebuke of Trump, told CNN that Trump's refusal to support a clean bill was going back on his word.

"The president completely reversed himself on that deal and now he's going off in a different direction. That kind of back and forth is at odds with the kind of stability that our country has usually stood for," Sanford said.

But Sanford supported the spending bill with the border money, prompting U.S. Sen. Brian Schatz, D-Hawaii, to tweet: "Elected Republicans characterizing the Presidents actions as dangerous and undemocratic and then voting with him is.. you pick the adjective .. but I will just say it is frustrating."

Itkowitz is a Washington Post columnist.