Lawmakers reelected Paul D. Ryan as House speaker Tuesday, choosing the Wisconsin Republican with a fraught history with President-elect Donald Trump to serve as Trump’s chief legislative partner.

Ryan won the support of all but one Republican, winning with many fewer GOP defectors than when he first won the speakership in 2015. The vast majority of Democrats voted for Rep. Nancy Pelosi (D-Calif.), who was reelected as party leader last year despite an abortive effort among some colleagues to oust her after November’s disappointing election results.

The near-unanimous vote for Ryan stands as a strong show of Republican unity as the party embarks on an ambitious legislative agenda that, for the first time in eight years, has a real chance to be signed into law.

But the 24 hours preceding the vote showed that unity can be fleeting: His reelection came less than two hours after Republicans held an emergency meeting to reverse proposed changes that would roll back the authority of the independent Office of Congressional Ethics. Ryan opposed those changes ahead of a Monday night conference meeting, but lawmakers voted for them anyway — then agreed to reverse course Tuesday after a public firestorm.

Addressing the House after his election, Ryan made a sharp call to action: “We are not here to be; we are here to do.”

“Millions and millions of Americans are deeply dissatisfied with their situation,” he said. “They have let out a great roar. … We hear you, we will do right by you and we will deliver.”

Rep. Thomas Massie (Ky.) was the only Republican not to cast his ballot for Ryan. Massie invoked a Trump campaign mantra as he voted for Rep. Daniel Webster (R-Fla.), saying Webster would “drain the swamp.”

Massie was one of nine Republicans who broke with Ryan in October 2015; seven of the remaining eight continue to serve in the House and supported Ryan on Tuesday.

Republicans currently enjoy a 241-to-194 advantage over Democrats in the House, though that margin stands to narrow slightly in the coming weeks as the Senate takes up nominations of several House members to the Trump administration. Should those members be confirmed, their seats would be filled through special elections to be held later this year.

Trump has picked Rep. Mick Mulvaney (R-S.C.) to serve as White House budget director, Rep. Mike Pompeo (R-Kan.) to serve as CIA director, Rep. Tom Price (R-Ga.) to serve as health and human services secretary, and Rep. Ryan Zinke (R-Mont.) to serve as interior secretary. One Democrat, Rep. Xavier Becerra (Calif.), is expected to depart the House soon to become his state’s attorney general.

Many Democrats prefaced their votes with a short script before casting their votes for Pelosi: “Because the people’s House should be ethical, accountable and open to free debate,” several of them said. Rep. John Lewis (Ga.), for one, delivered his vote from the well of the House.

One Republican had a sharp retort: “Because the people’s House should be in order, Paul Ryan,” said Rep. Mike Bost (R-Ill.).

Four Democrats opposed Pelosi: Rep. Kyrsten Sinema (Ariz.) voted for Lewis; Reps. Jim Cooper (Tenn.) and Kathleen Rice (N.Y.) voted for Rep. Tim Ryan (Ohio); and Rep. Ron Kind (Wis.) voted for Cooper.