WASHINGTON — In the small dining room next to the Oval Office where he works much of the time, President Trump keeps a stack of color-coded maps of the United States representing the results of the 2016 election. The counties he won are blotchy red and span most of the nation.

Mr. Trump sometimes hands the maps out to visitors as a kind of parting gift, and a framed portrait-size version was hung on a wall in the West Wing last week. In conversations, the president dwells on the map and its import, reminding visitors about how wrong the polls were and inflating the scope of his victory.

At the root of Mr. Trump’s unpredictable presidency, according to people close to him, is a deep frustration about attacks on his legitimacy, and a worry that Washington does not see him as he sees himself.

The Run-Up

The podcast that makes sense of the most delirious stretch of the 2016 campaign.

As he careens from one controversy to another, many of them of his own making — like his abrupt decision to fire the F.B.I. director, James B. Comey, who was leading an investigation into the president’s associates — Mr. Trump seems determined to prove that he won the election on his own. It was not Russian interference. It was not Mr. Comey’s actions in the case involving Hillary Clinton’s emails. It was not a fluke of the Electoral College system. It was all him.

He sits in the dining room or Oval Office stewing over the Russia inquiry that Mr. Comey was managing, arguing to anyone who will listen that the matter is all a Democratic-inspired conspiracy to undermine the validity of his victory. Even as he was defending his decision to dismiss Mr. Comey last week, Mr. Trump signed an executive order creating a commission to investigate voting fraud in a quixotic effort to prove his unsubstantiated contention that he would have won the popular vote against Mrs. Clinton but for millions of ballots that were illegally cast against him.

Mr. Trump burns with frustration over not getting enough credit for winning the nation’s highest office after having never so much as run for City Council or town alderman. He ran when pundits predicted he would not, stayed in when they were certain he would drop out, never lost his core supporters and, amid a dysfunctional campaign that was known for self-inflicted wounds, propelled himself to victory over the vastly more experienced Clinton machine. He expected to be celebrated for it, and that has not happened.

“There’s a lot of anger. I’ve talked with him about it,” said Christopher Ruddy, chief executive of Newsmax Media and a friend of Mr. Trump’s. “No other president in history has faced the barrage of press attacks, people calling for him to be impeached before he took the oath of office.”

“I think the way Trump looks at this is — the big club they’ve tried to get at him is the Russia collusion argument,” Mr. Ruddy added. “Trump sees this as a political attack, not a fair attack on him.”

In the process, allies and advisers said, Mr. Trump has only made the situation worse for himself. Rather than ignoring the Russia investigation and focusing on priorities like health care and taxes, he keeps drawing more attention to the subject with intemperate Twitter posts, angry interviews and actions like the firing of Mr. Comey.

He is so consumed by the matter that he studies congressional hearings on the Russia case, scrolling through them using TiVo. The night before dismissing Mr. Comey, he invited Time magazine journalists to dinner and, on a 60-inch-plus television he has had installed in the dining room, showed them various moments from the hearings, offering play-by-play-style commentary.

If Mr. Trump has nothing to hide, as he insists, he has only succeeded in making it appear as though he might. He seemed to almost invite comparisons to the Watergate scandal by firing Mr. Comey late in the day, then hosting Henry Kissinger in the Oval Office the next day. He offered contradictory explanations for his actions, making statements by his spokesmen inoperative, and finally made a veiled threat to Mr. Comey on Twitter, hinting that he might have secret tape recordings of their conversations.

“What we’ve really learned is either he’s worried about Russia because he’s got a significant vulnerability or he’s worried about Russia because it undermines his electoral win,” said Jennifer Palmieri, who was the communications director for Mrs. Clinton’s campaign. “He’s clearly been more preoccupied with it than we understood.”

Even setting aside the Russia investigation, Mr. Trump has seemed absorbed by his election victory, one that defied the odds and nearly all political prognostications. Since taking office, he has spoken regularly of his campaign triumph, even at events where it might not have seemed fitting, as during a visit to C.I.A. headquarters to discuss national security. In his first days in office, he was fixated on the size of his inauguration crowd.

He still exults over the win. “November 8, wasn’t that a great evening?” he asked a couple of weeks ago at the National Rifle Association. At times, he still seems surprised about the results. At an event in the Rose Garden to celebrate a House vote on his health care legislation, he turned to Republican lawmakers. “How am I doing?” he asked. “Am I doing O.K.?” Then, answering his own question, he said: “I’m president. Hey, I’m president. Can you believe it?”

When Jeanine Pirro of Fox News asked him about the health care legislation in an interview on Friday, Mr. Trump drifted back to the election, talking not only about how he had won but also about how Republicans had kept control of both houses of Congress. “We were supposed to lose all three,” he said, though few analysts expected the party to actually lose the House. But instead, “I worked very hard, and we ended up winning all three.”

The day before, in an interview with Lester Holt of NBC News, Mr. Trump returned to another favorite assertion to explain why Democrats were mad about his victory and therefore promoting what he called a false story about Russian meddling and possible collusion with his team. “The Electoral College is almost impossible for a Republican to win,” he said. “It’s very hard because you start off at such a disadvantage. So everybody was thinking they should’ve won the election. This was an excuse for having lost an election.”

Political specialists would actually say the opposite — that Republicans have a disproportionate advantage in the Electoral College, given the extra weight it gives to less-populated states and the ability of Republicans to win it twice in the past 16 years without also winning the popular vote. Either way, Mr. Trump’s point is that he won, Democrats should get over it and the F.B.I. and congressional committees should drop their investigations.

A week before firing Mr. Comey, the president posted on Twitter to challenge Mrs. Clinton’s contention that she had lost in part because of Mr. Comey’s announcement shortly before the election that he was reopening the bureau’s investigation into her emails.

“FBI Director Comey was the best thing that ever happened to Hillary Clinton in that he gave her a free pass for many bad deeds!” he wrote. “The phony Trump/Russia story was an excuse used by the Democrats as justification for losing the election. Perhaps Trump just ran a great campaign?”

Former aides to Mrs. Clinton said that Mr. Trump obviously could not let go. “It is remarkable,” said Ms. Palmieri, her former adviser. “Has there been a president ever who’s been that obsessed about proving that he’s legitimate?”

Mr. Ruddy argued that, from Mr. Trump’s point of view, it was the other side that could not move on. “He is totally secure with the idea that he won this election fair and square,” Mr. Ruddy said.

Other presidents have basked in their electoral victories and have seized on various data points to argue that theirs was greater than others. But few seem to have relived their elections and relitigate them as persistently as Mr. Trump has.

After President George W. Bush lost the popular vote in 2000 but won the narrowest of Electoral College victories after the Supreme Court stopped a hotly disputed Florida recount, he did not publicly dwell on the way he had gotten into office.

Instead, Mr. Bush plowed forward with his agenda and put the election behind him, rarely speaking of it again. He also made a point of reaching out to Democrats in the early days of his administration on issues like education and tax cuts to try to heal some of the wounds caused by the election, eventually winning bipartisan votes on major legislation in his first year.

“He knew he won, but he knew many people didn’t see him as a legitimate president and needed to reach out,” said Matthew Dowd, a senior strategist for Mr. Bush in 2000 and chief strategist for his 2004 re-election campaign. “But he didn’t look back in any kind of insecurity because he knew he could only control what was happening today or in the future.”

For Mr. Trump, what is happening today is still about what happened last year. Check out the map.