WASHINGTON — A day after Democrats recaptured the House, Representative Nancy Pelosi, the longtime party leader, promised to work with President Trump and Senate Republicans on issues where they could agree, while vowing the new majority would assert itself when necessary.

“We have a responsibility to find common ground where we can,” Ms. Pelosi, of California, said Wednesday in an interview. “If not, we stand our ground.”

It did not take Mr. Trump long to test Ms. Pelosi’s resolve, abruptly firing Attorney General Jeff Sessions. Democrats were alarmed, worried that the president was moving toward shutting down the special counsel’s investigation into Russian interference in the 2016 election.

The turn of events encapsulated the conflicting pressures on Ms. Pelosi and her new Democratic majority. Voters in traditionally Republican districts in the suburbs joined those in more heavily Democratic communities to elevate Democrats to power as a check on Mr. Trump after he spent the past two years largely unconstrained by a compliant House and Senate led by Republicans.