ISTANBUL — The attack was brazen in its aim and execution, targeting some of the world’s most vital oil infrastructure with a barrage of missiles and drones and potentially inviting a fierce American response.

But for Iran, which U.S. officials believe staged the weekend assault on Saudi oil facilities, the gamble of such a mission may have been worth the risk. 

Tehran denies playing a role in the blitz, which crippled Saudi Arabia’s oil output. But analysts say Iran likely wanted to test a key adversary and jolt global energy markets, building leverage ahead of potential talks with the United States. 

Iran’s leaders may have bet that President Trump, wary of Middle East conflicts, would decline to respond with force and that the crisis instead might prompt world powers to intervene — and push the United States to lift its crippling economic sanctions on Tehran, according to analysts.

Now Iran, facing an economic crisis, appears to have raised the stakes. It is a strategy, analysts say, that reflects the hardening stance of Iran’s rulers. 

“Iranian elites have tacked to a harder-line, more risk-acceptant policy. . . . Iranian policy changed from ‘wait out Trump’ to ‘shoot back at Trump,’ ” said Ayham Kamel, head of Middle East research at the political risk firm Eurasia Group. “The bold policy does not mean Iran wants war,” he said, adding that Tehran maintains “respect for and fear of U.S. military power.” 

But, he said, “it does mean that moving forward, Iran won’t shy away from the edge of the envelope.”

Iran’s new policy seeks to inflict pain on U.S. allies and showcase Iranian power, analysts say, but without stoking a direct conflict with the United States.

U.S. and Saudi officials have concluded that weaponized drones and guided cruise missiles, possibly fired from Iranian territory, evaded the kingdom’s air ­defenses to carry out precision strikes against oil installations ­belonging to the Saudi oil giant, Aramco. Yemen’s Houthi rebels, who are allied with Iran, claimed responsibility, though U.S. and Saudi officials say they lack the capability to carry out such a complex attack. 

According to Behnam Ben Taleblu, a senior fellow at the Foundation for Defense of Democracies, Iran may have been emboldened by Trump’s reluctance to take military action against Tehran in June, when Iran downed a U.S. Navy spy drone over the Strait of Hormuz. 

Trump ordered, then called off a military strike on Iranian targets, saying the response would have been disproportionate.

“Trump is not willing to start a military attack against Iran,” Naser Imani, a former member of the political bureau of Iran’s Revolutionary Guard Corps, wrote in the conservative news outlet Alef this week. 

The most recent escalation in Persian Gulf violence came, perhaps ironically, just after John Bolton, one of the strongest White House voices for confrontation with Iran, resigned as Trump’s national security adviser.

With the Houthi rebels claiming responsibility for the weekend strikes, Tehran may have been hoping to have plausible deniability, analysts say.

“It does not matter where the drones came from. What matters is that the expensive Saudi anti­aircraft systems could not stop a group of drones from targeting one of their most important facilities,” Imani wrote. “The advanced American weapons could not guarantee their security.”

For more than a year, since Trump withdrew from the 2015 Iran nuclear deal negotiated between Iran and world powers, Tehran has calibrated its response to ramped-up U.S. pressure. The agreement had aimed to restrict Iran’s nuclear program in return for sanctions relief. The Trump administration reimposed sanctions, declaring a near-total embargo on the Iranian economy. 

Iran has encouraged European nations who are also signatories to the deal to help offset the financial impact of the U.S. withdrawal. But as Europe faltered and Iran’s oil sales plummeted, Tehran changed tack in the spring, warning it would begin reducing its commitments under the nuclear deal. 

Since then, Iran has taken ever bolder action, including boosting its uranium enrichment and harassing oil tankers in the Strait of Hormuz. Over the summer, the United States blamed Iran for explosions targeting commercial vessels in the Persian Gulf — a charge Iranian officials deny.

“The ‘art’ of this sort of escalation revolves around staying just below certain thresholds for your adversary’s use of force,” Taleblu said of Iran’s apparent strategy. 

At each juncture, however, the risk of miscalculation grows, he said. 

“For the time being, Iran appears to have achieved most of its objectives,” said Ali Alfoneh, senior fellow at the Arab Gulf States Institute in Washington. These include strengthening its negotiating position with the United States, displaying its power in the region and, potentially, showing Saudi Arabia that the United States would not come to its aid in a meaningful way.

As a result, he said, Tehran “is likely to engage in riskier maneuvers in an attempt to persuade Washington to remove the sanctions regime.”