Mr. Trump said that some people believed that he could pick up a single Electoral College vote in the northernmost of the state’s two districts. But in an auditorium in Portland’s City Hall, Mr. Trump said he was hopeful about turning the whole state red for the first time since 1988.

“We have such incredible people up here,” he said. “We have people that like Donald Trump.”

He drew rounds of applause with now-familiar riffs about keeping dangerous refugees out of the United States and building a wall on the border with Mexico. Attacking President Obama for arranging a large financial payment to Iran, Mr. Trump described seeing a video of a plane landing in Iran bearing cash in several currencies — even though there is no evidence that such a video exists. (At a news conference shortly after, Mr. Obama denounced criticism by Mr. Trump and others of the payments.)

Mr. Trump told supporters that Mr. Pence had come to seek his permission before endorsing Mr. Ryan. “He said, ‘I like him, he’s a friend of mine, would you mind if I endorsed him, and I will not do it if you say no,’” Mr. Trump said. “I say, ‘Mike, you like him? Yes. Go ahead and do it.”

Yet Mr. Trump found a turbulent reception inside and outside the hall, where a crowd of demonstrators assembled. Several held up signs describing Mr. Trump as a fascist, and a few women held placards quoting Margaret Chase Smith, a Maine senator who vocally opposed Joseph McCarthy in the 1950s.

During his remarks, Mr. Trump drew interruptions from the demonstrators who silently held up miniature copies of the Constitution, some of them with the logo of the American Civil Liberties Union on the back. As they were escorted out, the protesters faced jeers from Mr. Trump’s supporters; several said they had been jostled or had their pocket Constitutions snatched away.

Julia Legler, one of more than a dozen demonstrators, said the group objected to “Islamophobic, anti-Muslim garbage” emanating from the Trump campaign. She said their inspiration was Mr. Khan.