President Trump appeared to be softening toward Iran. He had broken with his administration’s leading advocate of confrontation, signaled a willingness to meet personally with his Iranian counterpart, and reportedly considered relaxing some sanctions.

But Iran, American officials say, responded with violence. The officials have accused Iran of orchestrating or even starting a major attack on Saturday against critical Saudi Arabian oil installations, jolting international energy markets and humiliating a key American ally.

The slap-the-other-cheek tactic is hardly surprising, Iranian scholars say. Tehran, they said, has concluded that its recent aggressions have effectively strengthened its leverage with the West and in the region. And despite his occasional outburst of threats, Mr. Trump is deeply reluctant to risk an open-ended military confrontation in the Middle East that would endanger world oil supplies in the middle of a re-election campaign.

“Iranian hard-liners consider Trump’s inconsistency to be weakness,” said Ali Ansari, a professor of Iranian history at the University of St. Andrews in Scotland. For Iranian hard-liners, he said, “their policy of ‘maximum resistance’ is working.”