Nancy Pelosi on Thursday narrowly won re-election as House speaker after more than a dozen Democrats either voted for someone else or voted "present."

Pelosi, D-Calif., won in a 220-192 vote that took place just moments after the 116th Congress was assembled. She needed a majority of those who voted for a named candidate, or 216 votes, to win. She defeated Rep. Kevin McCarthy, R-Calif., who will be House Minority Leader in the new Congress.

Twelve Democrats voted for another candidate, and three others voted "present."

Her close victory came after many Democrats agreed to back her when she agreed to give up the gavel after two more terms at most.

One of the Democrats who voted "present," Rep. Jim Cooper of Tennessee, said his vote was meant to register his push for a new leadership slate.

“Today I voted 'present' in the vote for Speaker of the House, consistent with my eight-year push for new Democratic leadership,” Cooper tweeted. “Now that we are back in the majority, I did not vote for a rival candidate because there are none.”

Despite the narrow victory, Pelosi, 78, is now poised to become the oldest House Speaker in history in 2020 during the second session of this Congress.

She is the first lawmaker since Sam Rayburn to serve non-consecutive terms as speaker. Rayburn held the gavel from 1949-1953 and from 1955 until 1961, when he died in office.

Pelosi served as speaker from 2007 until 2011, when Republicans retook the majority.

Rep. Hakeem Jeffries, D-N.Y., who chairs the Democratic caucus and is a rising star within the party, nominated Pelosi with praise for her first run as speaker, when she played an instrumental role in passing Obamacare and other Democratic agenda items.

"In the 116th Congress, she will continue to fight hard for the people," Jeffries said. "Nancy Pelosi will fight to lower health care costs, strengthen the Affordable Care Act, protect people with pre-existing conditions and increase pay for everyday Americans."

"Pelosi will also pass a plan to rebuild the nation's infrastructure and end the era of voter suppression once and for all," Jeffries said.

Republican Conference Chair Liz Cheney, R-Wyo., daughter of former Vice President Dick Cheney and new to the GOP leadership, nominated Rep. Kevin McCarthy, R-Calif. But McCarthy was destined to serve as minority leader because Democrats hold the majority and more votes to elect Pelosi.

Pelosi returns to the most powerful position in Congress as the head of a more progressive faction of Democrats who are eager to push the party agenda further left.

Newcomer Democrats including Rep. Alexandria Ocasio-Cortez, D-N.Y., want the House to approve expanded Medicare coverage and legislation aimed at eliminating fossil fuels and promoting green energy, among other progressive proposals.

Pelosi will also have to fend off efforts by many progressives in her caucus who want to impeach President Trump. Pelosi said she’s more interested in promoting a Democratic agenda rather than trying to oust the president.

Pelosi must first take on a partisan battle over fully funding the government for this fiscal year. The House on Thursday is expected to approve bills funding the unfunded parts of the government, without any of the $5 billion Trump is looking for to build a border wall.

But those bills aren't expected to go anywhere in the Senate, and Pelosi and party leaders from both chambers are scheduled to meet Friday with Trump for another attempt to negotiate a solution. Democrats are refusing to support money to build a southern border wall, and Trump has pledged not to sign another spending bill that does not include wall funding.

On Friday, Pelosi will call up a reform bill that would, among other things, force Trump to disclose his tax returns.

The legislation would also restore the Voting Rights Act, which was partly nullified by the Supreme Court, and would install new campaign finance disclosure rules, among other provisions.

But unlike her first years as speaker, when Democrats controlled both Congress and the White House, Pelosi will have little chance of moving her agenda beyond the lower chamber.

The Senate remains under the control of Republicans, who have expressed little interest in passing progressive policies.

Trump, however, has expressed strong interest in working with Pelosi on common goals such as infrastructure and lowering prescription drug prices. But Trump has also warned that his cooperation depends on whether Democrats spend the next two years trying to impeach him.

CORRECTION: Due to an editing error, a previous version of this story erroneously said more than two dozen Democrats voted against Pelosi and identified Rep. Hakeem Jeffries of New York as a Republican. Twelve Democrats voted for another candidate, and three others voted "present." Jeffries is a Democrat. The Washington Examiner regrets the error.