WASHINGTON – Nancy Pelosi, the only woman to have ever served as House speaker, was re-elected to the post on Thursday as Democrats took control of the House after eight years in the minority.

“Our nation is at an historic moment,” the California Democrat said. “Two months ago, the American people spoke, and demanded a new dawn.”

With a big boost from female voters, Democrats won a net 40 seats in the House in November's midterm elections. That was their biggest gain since the post-Watergate election of 1974 when Democrats picked up 49 seats.

The midterm elections ushered in a record number of women and racially diverse lawmakers.

The shift in power in the House sets the stage for an era of divided government, with Democrats poised to clash with the Republican-dominated Senate and President Donald Trump on issues ranging from immigration to the budget to ongoing investigations involving the president and members of his administration.

Already, House Democrats and Trump are locked in an impasse over the budget and border security that has left parts of the federal government shutdown for the past 13 days.

In the Senate, Republicans expanded their narrow majority by two seats.

Pelosi, 78, who served as House speaker from 2007 to 2011 and minority leader before and after that, is one of just a handful who have won multiple terms as speaker.

After being elected, Pelosi hugged fellow female lawmakers as she made her way to the well of the House. Women and young girls filled most of the first few rows of seats on the House floor.

Pelosi's grandchildren hugged her as she received a standing ovation from lawmakers and from guests watching from the House gallery when her victory was announced. It was achieved without the help of 15 Democrats, some of whom voted "present" while others voted for someone else.

Pelosi garnered 220 votes to GOP Rep. Kevin McCarthy's 192.

Lawmakers whipped out cellphones to snap pictures of Pelosi as McCarthy, a fellow Californian, handed over the gavel.

When it was time to swear in the 116th Congress, the contrast in the chamber was striking as members stood to raise their right hands.

On one side was a sea of mostly white men in dark suits.

On the other were brown and white faces and scores of women clad in bright red dresses and white pants suits.

In her speech, Pelosi pledged that the House "will be transparent, bipartisan and unifying."

She called for addressing income disparities and for ending “inaction and denial of science” to address the “existential threat of our time: the climate crisis.”

And she said the House will work to lower health care costs, protect people with pre-existing conditions, rebuild America with “green” infrastructure, and pass legislation to boost ethics in government.

No 'excuse for gridlock'

McCarthy said the divided government should not be an "excuse for gridlock or inaction."

The clerk announced the receipt of credentials of members, noting that a North Carolina Republican, Mark Harris, who faces allegations of election fraud, would not be seated.

New York Rep. Hakeem Jeffries, the chairman of the House Democratic Caucus, nominated Pelosi, crediting her with everything from rescuing the auto industry to saving Social Security. And, he said, “Nancy Pelosi is just getting started.”

“Let me be clear, House Democrats are down with N.D.P,” referring to Pelosi's full name, Nancy D’Alesandro Pelosi.

As the votes were cast for speaker, a number of Democrats did not back Pelosi, while others were zealous in their support.

Pelosi sat next to House Majority Leader Steny Hoyer, D-Md., and glanced over at his shoulder as he appeared to be keeping a running tally of the votes.

Moderate Democrat Jim Cooper, who represents Nashville, Tennessee, voted "present," saying his stance is consistent with his eight-year push for new Democratic leadership. Plus, there was no rival Democratic nominee to support.

But fellow Tennessean, Rep. Steve Cohen, who represents Memphis, said he was voting for Pelosi to "make America great again" – a reference to Trump’s signature political slogan.

Meanwhile, several female Democratic House members wore all white, the symbol of the women’s suffrage movement. This two-year Congress will be in session on the 100th anniversary of women winning the right to vote in 1920.

When Rep. Liz Cheney, R-Wyo., nominated McCarthy to be the speaker, Republicans stood and cheered as she called for a wall to be built along the border with Mexico.

Democrats just stared.

In his invocation to mark the beginning of the new Congress, Rep. Emanuel Cleaver, D-Mo., who is a pastor in the United Methodist Church, pleaded with House members to “rise above political selfishness.”

“We need thee every hour. Oh Lord, how we need thee,” Cleaver said.

More:Nancy Pelosi's granddaughter steals the show as House elects her grandmother as speaker

More:Exclusive: Nancy Pelosi vows 'different world' for Trump, no more 'rubber stamp' in new Congress

More:Trump vs. Pelosi: The standoff that will define Washington begins today

Decrying the shutdown

Sen. Mitch McConnell, R-Ky., marked his return as majority leader of a Senate in which the GOP widened its control of the body to 53 seats by extolling the accomplishments of the previous session and questioning whether a divided Congress would be frozen in political gridlock.

“It’s a clear choice and will be clear to the American people watching all this at home," McConnell said. "Good governance or political performance art? The public interest or political spite? Policymaking or presidential harassment?”

Democratic Minority Leader Sen. Charles Schumer of New York spent most of his remarks decrying the shutdown of the federal government.

“Only one person is to blame for this predicament: President Trump,” he said.

The scene on the House floor had the look of an over-sized family reunion with people greeting each other with hugs and kisses. Many brought their children, including infants, on the floor with them. Boys in suit jackets and ties and girls in white tights and silver shoes wriggled into armchairs far too big for them. Two children sat on the lap of freshman Rep. Antonio Delgado, D-N.Y., as he read them a book.

Freshman Rep. Ilhan Omar, D-Minn., one of the first Muslim women in Congress, greeted and hugged other members, milling about in a red and orange hijab. She is the first woman in Congress to wear the Muslim head covering. Democrats voted on new rules, including clarifying that the prohibition on wearing hats in the House does not apply to religious headwear.

Pelosi, wearing a bright fuchsia dress, swept into the House with two young children in tow.

The list of her guests for the events included her five children and nine grandchildren, as well as singer Tony Bennett and his wife, Susan Benedetto; Mickey Hart of the Grateful Dead rock group and his wife, Caryl Hart; and television personality Tim Gunn.

Bennett sang to Pelosi on the eve of her expected election as speaker, at a dinner hosted by Italy’s ambassador to the United States.

Centrist rebellion quelled

Pelosi faced opposition in her bid for speaker, but she stamped out a centrist rebellion by agreeing to limit her term to just four more years. Rep. Marcia Fudge, D-Ohio, considered challenging Pelosi for the top spot – until Pelosi announced that Fudge would chair a subcommittee focused on elections and voting issues, one of her signature issues.

The new Democratic House is expected to vote later on a measure to end the shutdown, though Trump has already rejected it because it does not include the more than $5 billion he is demanding for the construction of a wall along the U.S.-Mexico border.

Also as part of the first day of business, Democrats took up a package of rules changes. They ranged from those encouraging diversity to tougher ethics rules and tweaked legislative procedures that will make it easier to raise taxes.

Pelosi secured some votes to become speaker by agreeing to changes aimed at easing the passage of bills with broad bipartisan support. That provision even earned the package the support of Republican Rep. Tom Reed of New York, who said Wednesday he would take the rare step of crossing party lines to vote for it.

But the changes still faced opposition from some liberal members who argued new budget rules will make it harder to expand social programs.

Three Democrats voted against the bulk of the rules changes and three Republicans supported them.

More women will serve this Congress than ever before, with 25 in the Senate and 102 in the House, according to the Center for American Women and Politics at Rutgers University.

The House will also have the largest number of women of color ever, plus the youngest woman ever elected to Congress – Democratic activist Alexandria Ocasio-Cortez, of New York, who turned 29 in October.

Their historic involvement follows the massive Women’s March to resist Trump’s presidency and the #MeToo Movement's protest against sexual misconduct in the workplace.

In another nod to diversity, Democrats chose Rep. Jim Langevin, the first quadriplegic elected to Congress, to preside over opening day. The speaker’s rostrum was reconfigured in 2010 with a series of lifts to make it wheelchair accessible.

The freshman class in the House brings a record level of educational attainment, but is also the least politically experienced cohort in modern history, according to the Brookings Institution.

Contributing: Bill Theobald, David Jackson and Eliza Collins