Putin’s role as intermediary between Riyadh and Tehran was pivotal, testament to the rising influence of Russia in the Middle East since its military intervention in the Syrian civil war just over a year ago.

It started when Putin met Saudi Prince Mohammed in September on the sidelines of a G20 gathering in China.

The two agreed to cooperate to help world oil markets clear a glut that had more than halved oil prices since 2014, pummelling Russian and Saudi government revenues. Oil prices are up 10 pct this week topping USD53 a barrel.

The financial pain made a deal possible despite the huge political differences between Russia and Saudi over the civil war in Syria.

"Putin wants the deal. Full stop. Russian companies will have to cut production," said a Russian energy source briefed on the discussions.

In September, OPEC agreed in principle at a meeting in Algiers to reduce output for the first time since the 2008 financial crisis.

But the individual country commitments required to finalise a deal at Wednesday's Vienna meeting still required much diplomacy.

Recent OPEC meetings have failed because of arguments between de facto leader Saudi Arabia and third-largest producer Iran. Tehran has long argued OPEC should not prevent it restoring output lost during years of Western sanctions.

Proxy wars in Syria and Yemen have exacerbated decades of tensions between the Saudi Sunni kingdom and the Iranian Shi'ite islamic republic.

Brinkmanship

Heading into the meeting, the signs were not good. Oil markets went into reverse. Saudi Prince Mohammed had repeatedly demanded Iran participate in supply cuts. Saudi and Iranian OPEC negotiators had argued in circles in the run-up to the meeting.

And, then, just a few days beforehand, Riyadh appeared back away from a deal, threatening to boost production if Iran failed to contribute cuts.

But Putin established that the Saudis would shoulder the lion's share of cuts, as long as Riyadh wasn't seen to be making too large a concession to Iran. A deal was possible if Iran didn't celebrate victory over the Saudis.

A phone call between Putin and Iranian President Rouhani smoothed the way. After the call, Rouhani and oil minister Bijan Zanganeh went to their supreme leader for approval, a source close to the Ayatollah said.

"During the meeting, the leader Khamenei underlined the importance of sticking to Iran's red line, which was not yielding to political pressures and not to accept any cut in Vienna," the source said.

"Zanganeh thoroughly explained his strategy ... and got the leader's approval. Also it was agreed that political lobbying was important, especially with Mr. Putin, and again the Leader approved it," said the source.

On Wednesday, the Saudis agreed to cut production heavily, taking "a big hit" in the words of energy minister Khalid al-Falih - while Iran was allowed to slightly boost output.

Iran's Zanganeh kept a low profile during the meeting, OPEC delegates said. Zanganeh had already agreed the deal the night before, with Algeria helping mediate, and he was careful not to make a fuss about it.

After the meeting, the usually combative Zanganeh avoided any comment that might be read as claiming victory over Riyadh.

"We were firm," he told state television. "The call between Rouhani and Putin played a major role ... After the call, Russia backed the cut."

Iraq last-minute hitch

But OPEC would not be OPEC without a last-minute quarrel threatening to derail the deal. Iraq became a problem.

As ministerial talks got underway, OPEC's second-largest producer insisted it could not afford to cut output, given the cost of its war against Islamic State.

But, facing pressure from the rest of OPEC to contribute a cut, Iraqi Oil Minister Jabar Ali al-Luaibi picked up the phone in front of his peers to call his prime minister, Haider al-Abadi.

"Abadi said: 'Get the deal done'. And that was it," one OPEC source said.