The US offered to take military action on behalf of the 15 British sailors and marines held by Iran, including buzzing Iranian Revolutionary Guard positions with warplanes, the Guardian has learned.

In the first few days after the captives were seized and British diplomats were getting no news from Tehran on their whereabouts, Pentagon officials asked their British counterparts: what do you want us to do? They offered a series of military options, a list which remains top secret given the mounting risk of war between the US and Iran. But one of the options was for US combat aircraft to mount aggressive patrols over Iranian Revolutionary Guard bases in Iran, to underline the seriousness of the situation.

The British declined the offer and said the US could calm the situation by staying out of it. London also asked the US to tone down military exercises that were already under way in the Gulf. Three days before the capture of the 15 Britons , a second carrier group arrived having been ordered there by president George Bush in January. The aim was to add to pressure on Iran over its nuclear programme and alleged operations inside Iraq against coalition forces.

At the request of the British, the two US carrier groups, totalling 40 ships plus aircraft, modified their exercises to make them less confrontational.

The British government also asked the US administration from Mr Bush down to be cautious in its use of rhetoric, which was relatively restrained throughout.

The incident was a reminder of how inflammatory the situation in the Gulf is. According to some US and British officers, there is already a proxy war under way between their forces and elements of the Iranian Revolutionary Guard.

Meanwhile, the Iranians are convinced that separatist guerrilla attacks in Khuzestan and Baluchistan provinces are the work of British and US intelligence respectively. Earlier this week, ABC television news reported that a Baluchi group, Jundullah, based in Pakistan and carrying out raids inside Iran, had been receiving advice and encouragement from American officials since 2005.

A senior Iranian source with close ties to the Revolutionary Guard, told the Guardian: "If this had been between Iranian and American soldiers it could have been the beginning of an accidental war."

With the crisis now over, a remarkable degree of consensus is emerging among British, Iranian and Iraqi officials about what happened over 13 nervous days - namely that the decision to seize the Britons was taken locally, and was not part of a grander scheme cooked up in Tehran.

"My best guess is that this was a local incident which became an international incident," said one British source closely involved in the crisis.

Both sides had been watching each other closely for years across the disputed line separating the Iranian and Iraqi sides of the Shatt al-Arab waterway and the northern Gulf beyond and British officials say that Iranian boats regularly infringe on foreign waters.

The senior Iranian source meanwhile, claimed there had been three British incursions into Iranian waters in the three months leading up to the capture and that the decision to detain the British naval crew on March 23 was taken by a regional Revolutionary Guard commander, responsible for the waterway.

Once the 15 captives were brought back to Iran, their stay was guaranteed to be unpleasant. The Pasdaran (as the Revolutionary Guards are universally known in Farsi) are a law unto themselves, feared within Iran for their thuggish methods.

There is also general agreement in London and Tehran that once the crisis had been triggered it took nearly two weeks to untangle, because their release had to be agreed by all the key players in the perpetual poker game that passes for government in Tehran. But those players could not be reached because they were scattered around the country for the No Rouz (new year) holiday.

"Nobody who counted was answering the phone," said one senior British official. "By the time the Iranian leaders got back from the holiday [on Tuesday] the phone was ringing off the hook, including from people they didn't expect, calling on them to release the captives quickly."

Among those unexpected callers were their closest allies, the Syrians, as well as leaders from far-flung states with no direct stake in the Gulf. Even the Colombian government issued a protest.

Another surprise intervention came from the Vatican. Hours before Wednesday's release, a letter from Pope Benedict was handed to Iran's supreme leader, Ayatollah Ali Khamenei. It said the Pope was confident that men of goodwill could find a solution. He asked the supreme leader to do what he could to ensure that the British sailors and marines were reunited with their families in time for Easter. It would, he said, be a significant religious gesture of goodwill from the Iranian people.

What impact the Pope's message had is impossible to assess. But some of its language was reflected at the press conference at which the release of the 15 Britons was announced. President Mahmoud Ahmadinejad said the decision to "forgive" the sailors and marines had been taken "on the occasion of the birthday of the great prophet [Muhammad] ... and for the occasion of the passing of Christ".

The Iraqi government also played a critical role, pushing for consular access to five Iranians who had been arrested by US forces in Irbil and had been in custody since January, and helping organise the mysterious release of an Iranian diplomat who had been in captivity since February.

In the first days of the crisis, Iraqi officials also helped the British to identify the exact boundaries of Iraqi waters, the Guardian has learned, suggesting the British were not as certain of their case as they had publicly claimed.

But it was the unexpected release of Jalal Sharifa, the second secretary at the Iranian embassy, that raised most eyebrows, fuelling speculation that some kind of bargaining was going on. The diplomat had been missing since he was plucked from the streets of Baghdad on February 4. Iran blamed US forces in Iraq for ordering the diplomat's abduction, but US military officials denied the claims. Baghdad's foreign minister, Hoshyar Zebari, however, has insisted that negotiations over Mr Sharafi had been under way long before March 23.

Some credit for the abrupt release of the British naval crew has also been given to Tony Blair's top foreign policy adviser, Sir Nigel Sheinwald, who got through to his Iranian counterpart, Ari Larijani for the first time the night before Mr Ahmadinejad made his surprise announcement. The opening of a Sheinwald-Larijani channel of communication is being hailed as one of the few pluses to emerge from the affair.

The crucial decision for release was taken on Tuesday by the supreme national security council. It includes representatives of the presidency, the armed forces and the Revolutionary Guard, and Tuesday was the first day they could all be brought together following the No Rouz holiday.

"I think they realised pretty quickly the game was not worth the candle," a senior British government source said.