“That’s not the situation here,” Mr. Obama said.

As Mr. Obama condemned Mr. Trump, the Republican candidate — apparently unaware of the president’s remarks — repeatedly criticized his Democratic opponent, Hillary Clinton, and the president in an hour of remarks. He called Mrs. Clinton a “liar” and a “thief” and said the country would be “finished” if voters chose four more years of a presidency like Mr. Obama’s. Mr. Trump also accused Mrs. Clinton of repeatedly lying over the weekend when she told Chris Wallace on “Fox News Sunday” that James B. Comey, the F.B.I. director, had said her statements about her private emails were truthful.

“I mean, she lied,” Mr. Trump said, prompting cries of “Lock her up!” from his supporters. “She, pure and simple, she only knows to lie. She really does. She only knows to lie. But she lied, and it’s a big story.”

Mr. Comey, testifying last month to Congress, said that “we have no basis to conclude she lied to the F.B.I.” But he also said he could not say whether Mrs. Clinton’s many public statements on the issue were truthful.

Mr. Trump, in a written statement meant to respond directly to the president’s remarks, called Mrs. Clinton “unfit to serve in any government office.” He also accused Mr. Obama and Mrs. Clinton of allowing Americans to be slaughtered in Benghazi, Libya; letting veterans die waiting for medical care; and releasing immigrants into the United States to kill innocent people.

“Our nation has been humiliated abroad and compromised by radical Islam brought onto our shores,” Mr. Trump’s statement said. “We need change now.”

The dueling appearances by the president and the Republican candidate seeking to replace him escalated the heated political rhetoric in a race that had already devolved into a series of personal attacks and character assassinations. Mr. Obama cited Mr. Trump’s reaction to Captain Khan’s parents, Khizr and Ghazala Khan, as a principal reason for his extended remarks. Mr. Trump had criticized the Khans after they honored their son at the Democratic National Convention and urged people to vote for Mrs. Clinton.