Unlike on Tuesday, when thousands marched around the embassy in response to deadly American airstrikes over the weekend and some forced their way through the outer wall, the protesters did not get into the compound.

President Trump tweeted that Iran was responsible, writing: “They will pay a very BIG PRICE! This is not a Warning, it is a Threat.” Ayatollah Ali Khamenei, Iran’s supreme leader, responded with a taunt, saying Mr. Trump “can’t do anything.”

Analysis: While the aftermath of the attack seemed to be under control, it played to Mr. Trump’s longtime worry that American diplomats and troops in the Middle East are easy targets, and it highlighted the vulnerability his administration faces amid impeachment and an election year.