WASHINGTON — Speaker Nancy Pelosi hopped into her SUV on Wednesday for the short drive to the White House knowing full well that a presidential ambush awaited. President Trump was not “serious,” and needed a way out of negotiations over a $2 trillion infrastructure plan that he could not pay for, she told lawmakers at the Capitol an hour earlier.

But Mr. Trump’s offramp led to a topic Ms. Pelosi is trying to play down: impeachment.

If Mr. Trump’s preplanned Rose Garden explosion proved anything, it is that the president is willing to sacrifice his own stated policy agenda to keep “presidential harassment” front and center, and that the speaker, who wants to focus on policy, is leveraging decades of hard-won political capital to keep her party from pursuing an impeachment path that she believes could cost House Democrats their majority in 2020 and keep Mr. Trump in the White House.

The White House meeting, all three minutes of it, was only Ms. Pelosi’s second most important meeting on Wednesday morning. At 9 a.m., the speaker, seeking to head off a growing revolt by House Democrats calling for Mr. Trump’s impeachment, convened an all-hands meeting with her caucus to sell her members on her strategy of exhausting all legislative and legal avenues before taking up impeachment.

For now, she is guided by two political goals: protecting the 40 newly elected Democratic members, who largely come from moderate or conservative districts, and avoiding Mr. Trump’s traps. And Wednesday was a good day for her. A federal judge rejected Mr. Trump’s request to block congressional subpoenas for his banking records, the second such ruling this week and a boost to the speaker’s plea for patience as the House’s fight moves into the courts.