WASHINGTON — Speaker Nancy Pelosi does not believe President Trump can be removed through impeachment — the only way to do it, she said this week, is to defeat him in 2020 by a margin so “big” he cannot challenge the legitimacy of a Democratic victory.

That is something she worries about.

“We have to inoculate against that, we have to be prepared for that,” Ms. Pelosi said during an interview at the Capitol on Wednesday as she discussed her concern that Mr. Trump would not give up power voluntarily if he lost re-election by a slim margin next year.

Sitting in her office with its panoramic view of the National Mall, Ms. Pelosi — the de facto head of the Democratic Party until a presidential nominee is selected in 2020 — offered Democrats her “coldblooded” plan for decisively ridding themselves of Mr. Trump: Do not get dragged into a protracted impeachment bid that will ultimately get crushed in the Republican-controlled Senate, and do not risk alienating the moderate voters who flocked to the party in 2018 by drifting too far to the left.

“Own the center left, own the mainstream,” Ms. Pelosi, 79, said.

“Our passions were for health care, bigger paychecks, cleaner government — a simple message,” Ms. Pelosi said of the 40-seat Democratic pickup last year that resulted in her second ascent to the speakership. “We did not engage in some of the other exuberances that exist in our party” — a reference to some of the most ambitious plans advocated by the left wing of her party and some 2020 candidates, including “Medicare for all” and the Green New Deal, which she has declined to support.

Nearly five months into her second speakership, Ms. Pelosi appears to be embracing her role as the only Democrat with the power to oppose Mr. Trump. While she seems comfortable in waging battle with him, her unease about the president’s behavior has only intensified since the Democrats’ triumphal election.

Few people outside Ms. Pelosi’s inner circle were aware of how worried she was that Mr. Trump would try to stop the opposition party from taking control of the House unless the Democrats’ victory was emphatic enough to be indisputable.

“If we win by four seats, by a thousand votes each, he’s not going to respect the election,” said Ms. Pelosi, recalling her thinking in the run-up to the 2018 elections.

“He would poison the public mind. He would challenge each of the races; he would say you can’t seat these people,” she added. “We had to win. Imagine if we hadn’t won — oh, don’t even imagine. So, as we go forward, we have to have the same approach.”

In recent weeks Ms. Pelosi has told associates that she does not automatically trust the president to respect the results of any election short of an overwhelming defeat. That view, fed by Mr. Trump’s repeated and unsubstantiated claims of Democratic voter fraud, is one of the reasons she says it is imperative not to play into the president’s hands, especially on impeachment.

Over the past two weeks, Mr. Trump has ratcheted up the pressure on Ms. Pelosi, reiterating his intention to block current and former officials like the former White House counsel Donald F. McGahn II from testifying before Democratic committees. Meantime, Attorney General William P. Barr’s defiant testimony before the Senate Judiciary Committee has prompted Ms. Pelosi to declare that he committed “a crime” by contradicting his previous statements about interactions with the special counsel, Robert S. Mueller III.

The president seems energized by the confrontation, and he views the compliant Republican Senate majority — which is unlikely to convict him if the House brings impeachment proceedings — as a license to goad Ms. Pelosi’s team, according to two people familiar with the president’s thinking.

Ms. Pelosi remains committed to avoiding impeachment, but it is clear that she is losing patience. On Wednesday night, after focusing on House business during the day, she watched excerpts from Mr. Barr’s testimony at her residence in Washington’s Georgetown neighborhood.

She was incensed that Mr. Barr had seemingly contradicted an earlier claim, made before a House committee in April, that no one on Mr. Mueller’s team had taken issue with the attorney general’s four-page summary of the report’s findings. Mr. Barr’s refusal to testify before the House Judiciary Committee only amplified the speaker’s anger.

“When you’re looking at Barr, you just think, ‘How could he sell his soul — alleged soul — to Donald Trump,’” Ms. Pelosi told her whip team early Thursday, according to the detailed notes of a person in the room.

Having Mr. Barr as a political target is useful because it allows Democrats to focus their outrage, for a time, on him instead of the president. But increasingly, in public and in private, Ms. Pelosi is suggesting that Mr. Trump’s behavior rises to the level of impeachment, even if she views the process itself as unacceptably dangerous for Democrats.

The president has remained curiously polite to the speaker, even as the war between the branches intensifies. His catchall description of Ms. Pelosi is a respectful one — “tough” — and he has told congressional allies that he respects Ms. Pelosi more than her predecessor, Paul D. Ryan, because of her ability to keep backbenchers from hijacking her caucus.

“Maybe he knows that I pray for him,” she shrugged. “I pray that his heart will be open for good things, to help people instead of taking babies out of the arms of their mothers, for example.”

Ms. Pelosi laced Wednesday’s conversation with scathing descriptions of Mr. Trump’s fitness to serve as president, taking issue with his “attention span” and his “lack of knowledge of the subjects at hand” during their negotiating sessions — and saying his behavior “degrades” the country and “dishonors” the Constitution.

Ms. Pelosi laughed when asked how her father, Thomas D’Alesandro Jr., a Democratic mayor of Baltimore and a former congressman known for his political toughness, would have interacted with Mr. Trump.

“Well, it would be like they were speaking foreign languages,” she said. “I don’t think my father could have ever conceived of a president who would ignore his oath of office to the extent this president does.”

Ms. Pelosi also shared some thoughts about the expansive and expanding Democratic field of presidential candidates. Joseph R. Biden Jr. “took off because people know him,” she said. “They trust him.”

When asked whether Mr. Biden would pay a political price for his grilling of Anita F. Hill during the 1991 confirmation hearings for Justice Clarence Thomas, Ms. Pelosi shook her head in the negative and waved a hand dismissively.

More than anything, Ms. Pelosi is focused on pursuing center-left policies she thinks will help her party out in 2020 — a focus on pragmatic improvements to health care, ballot access, clean government, immigration and infrastructure, one that emphasizes beating Mr. Trump politically without obsessing over Mr. Trump personally.

In her mind, that means grinding away at initiatives that she hopes will help re-elect new members in battleground districts, even if it risks delivering some achievements for Mr. Trump, and angering some critics on the left.

Mr. Trump met this week with Ms. Pelosi and other Democratic leaders at the speaker’s request, and agreed to work on a $2 trillion package to repair the nation’s crumbling roads, bridges, sewer systems and waterworks, securing his commitment to expand broadband nationally and undertake an overhaul of the country’s antiquated power grid.

“I like the number you’ve been using, Nancy — $2 trillion,” Mr. Trump said, according to an aide who was present at the White House for the meeting. “I’ll lead on this.”

The interaction was cordial. At one point, the president plucked a box of white Tic Tacs from his suit jacket and offered it to the speaker, who shook out a couple for herself.

Later that night, Mr. Trump cheerfully phoned Ms. Pelosi to reiterate that he really wanted to do a deal — despite the likely opposition of many Senate Republicans and Mick Mulvaney, his interim chief of staff.

Ms. Pelosi reiterated her demand that Mr. Trump present her with a detailed plan on how to pay for it, and left feeling optimistic but unsure that the president had the focus to follow through.

“Well,” Ms. Pelosi said, “that’s an attention-span subject.”