Christmas has come early for Vladimir Putin.
The attacks on key Saudi Arabian oil installations last weekend—which took out about half of the Kingdom’s oil supply—have bumped up the price of oil, Russia’s most important export, created a new export opportunity for its military, and given the Kremlin the chance to expand its influence in the Gulf even further.
While developments on Wednesday appear to have taken some of the heat out of the crisis, the attacks have still left Russia with plenty of opportunity to grow further into a role—from which the U.S. appears to be withdrawing—as the essential mediator of the Middle East’s conflicts and the guarantor of its stability.
Saudi Arabia implicated Iran in Saturday’s attacks on the Kurais oilfield and Abqaiq processing plant for the first time on Wednesday, but stopped short of blaming the Islamic Republic for actually carrying it out.
Earlier, President Donald Trump had said he had instructed the Treasury Department to substantially expand sanctions against Iran, but had likewise stopped short of ordering military retaliation, dialling back his rhetoric from the weekend when he said the U.S. was “locked and loaded” and waiting only for Saudi approval to strike back.
Wednesday’s utterances left the oil market convinced that diplomacy, rather than war, would be the immediate outcome.
But Putin isn’t waiting for the U.S. to lead that dance. On Monday, he had already discussed the attacks in person with Iranian President Hassan Rouhani. And on Wednesday, he had called on Riyadh not to be bounced into action against Iran by Washington. In a telephone call, Putin urged Crown Prince Mohammed bin Salman to carry out “thorough and objective research” into the attacks, according to a Kremlin statement.
The same statement carried a gentle reminder of how important Russia’s cooperation with the Organization of Petroleum Exporting Countries has been in supporting oil prices for the last 18 months. Spokesmen confirmed later that the two had reaffirmed their commitment to those production ceilings.
That cooperation, which has taken over 1 million (mostly Saudi) barrels of oil a day off world markets, has underpinned a flourishing bilateral relationship. It has smoothed over—without completely ending—a bitter rivalry in Syria, where Russia has supported President Assad against mostly Sunni Muslim rebels, co-religionists of Saudi Arabia. Russian accusations of Saudi support for terrorism in its restive North Caucasus region have also become less frequent. And the Kingdom is now both a source of substantial foreign investment in Russia, filling some of the vacuum left by U.S. and European investors, and one of the biggest buyers of Russian wheat.
Indeed, economic relations between the two are now so well developed that Moscow, if push came to shove, would choose Riyadh over its long-time ally, Tehran, says Chris Weafer, managing director of consultants Macro Advisory in Moscow.
It’s telling, Weafer says, that there have been no reports of major exports of Russian military technology to Tehran in years, whereas Putin immediately offered to sell Riyadh its S-400 air defense system after the weekend attacks. The sale of the S-400 earlier this year to NATO member Turkey triggered a diplomatic crisis, forcing the U.S. to exclude it from the F-35 fighter program as, per the Pentagon, “F-35 cannot coexist with a Russian intelligence collection platform that will be used to learn about its advanced capabilities.”
The mere notion that the Kremlin could sacrifice a long-time ally, whose nuclear program it has fostered and defended at the UN for nearly two decades, illustrates how far Putin’s foreign policy has developed beyond a reflexive support for antagonists of the U.S.
“Supporting Washington’s enemies solely because they oppose the global hegemon does not reinforce your own position,” Dmitri Trenin, director of the Carnegie Endowment for International Peace, argued in a recent essay. “It creates additional problems.”
Nikolay Kozhanov, an analyst with Chatham House in London, argued in a research paper last year that this new approach had already borne fruit.
“There are few countries that can simultaneously sustain positive relations with Iran, Turkey, Syria, Saudi Arabia, Egypt and Israel, which makes Russia a perfect candidate to be a mediator in the region,” Kozhanov wrote.
But a Russian role as mediator “would have been unimaginable” a decade ago, Weafer told Fortune. It has only been made possible, he added, by the U.S.’s gradual withdrawal from the region and, more specifically, its pursuit of energy independence—and now, under Trump, ‘Energy Dominance’—through the shale boom.
The U.S. now produces over 20% more oil than Saudi Arabia and its net imports of crude have fallen from a peak of 13.4 million barrels a day in 2006 to just over half a million barrels a day currently. “So nice that our Country is now Energy Independent,” Trump said via Twitter on Wednesday (glossing over the fact that the U.S. is still a big gross importer of crude).
“Before the shale boom, it was always clear that the U.S. would protect the main oil producers, but its commitment to Saudi defense and to the Gulf in general is diminishing,” Weafer said. “The U.S. has changed its position in the Gulf and that has opened the door to the Russians.”
More must-read stories from Fortune:
—China is the world’s biggest coal user. Can it break the habit?
—How the energy industry is using data to decarbonize itself
—Why solar execs say the game is already over for non-renewable energy
—BP’s CEO says he’ll sell oil projects to meet Paris climate accord goals
—Listen to our audio briefing, Fortune 500 Daily
Subscribe to The Loop, a weekly look at the revolutions in energy, tech, and sustainability.