Predictably, there were deep partisan divisions over who was behaving poorly to whom. Democrats were focused on Mr. Trump’s handshake snub, which Ms. Pelosi later spotlighted on Twitter, along with a photograph of the president turning his back.

“Democrats will never stop extending the hand of friendship to get the job done #ForThePeople,” she wrote, using the party’s campaign slogan. “We will work to find common ground where we can, but will stand our ground where we cannot. #SOTU”

During the address, as Mr. Trump read from the teleprompter, Ms. Pelosi, dressed in white — the color of the suffragists, worn by many of the Democratic women in the chamber — could be seen behind him, paging through his speech. Practiced at maintaining a stone face (she served as House speaker alongside another Republican president, George W. Bush), she kept her lips pursed and her eyes down, mostly remaining seated as Republicans rose to give Mr. Trump one standing ovation after another.

But when Mr. Trump made mention of the First Step Act, the bipartisan legislation that overhauled criminal justice reforms, Ms. Pelosi clapped and rose to her feet.

The relationship between Ms. Pelosi and Mr. Trump has long been one of the most closely watched in Washington — and it began going downhill even before Ms. Pelosi became House speaker. Mr. Trump tried to undercut her during an Oval Office meeting shortly after Democrats swept to the majority in 2018. Ms. Pelosi would have none of it.

“Mr. President,” she shot back, “please don’t characterize the strength that I bring to this meeting as the leader of the House Democrats, who just won a big victory.” When the meeting was over, images of Ms. Pelosi leaving the White House in a swingy red coat quickly went viral.

From there, their interactions seemed defined by a series of memes and public spats. Ms. Pelosi called off last year’s State of the Union address because of the government shutdown, enraging Mr. Trump and prompting him to cancel a flight she had scheduled overseas. When his speech was rescheduled, Ms. Pelosi was captured smirking and clapping at the president. When they met in October, a White House photographer snapped an image of the speaker standing up and wagging her finger at the seated president while she lectured him.