Iranian President Mahmoud Ahmadinejad says 15 British naval personnel captured in the Gulf are free to leave.
Mahmoud Ahmadinejad met the crew including Faye Turney
He repeated Iran's view that the British sailors and marines "invaded" Iranian waters, but said they were being released as a "gift" to Britain.
They are expected to be handed to the British embassy in Tehran on Thursday morning before flying home.
British Prime Minister Tony Blair said the news would come as "a profound relief" to the crew and their families.
Iranian media said the British crew members "shouted for joy" on hearing the news.
The British embassy in Tehran said it had now seen the sailors for the first time, and it was arranging the details of their travel home. But it was not clear where they were spending the night.
Earlier, television pictures showed the Iranian president smiling, chatting and shaking hands with the crew at the presidential palace in Tehran.
He joked to one: "How are you? So you came on a mandatory vacation?"
The Britons were wearing suits, rather than the military uniform and tracksuits they wore in previous pictures. The one female crew member, Faye Turney, wore a blue headscarf and jacket.
An unidentified crew member said: "I'd like to say that myself and my whole team are very grateful for your forgiveness. I'd like to thank yourself and the Iranian people... Thank you very much, sir."
Mr Ahmadinejad responded in Farsi: "You are welcome."
Mr Ahmadinejad announced the decision to release the Britons at a news conference In Tehran.
He spoke at length, attacking the West over its policy in the Middle East, and it was more than an hour before he even mentioned the captives issue.
He repeated allegations that the Britons were captured in Iranian waters, and awarded medals to the Iranian commanders responsible for detaining them.
It was all part of the build up to his extraordinary theatrical gesture, says the BBC's diplomatic correspondent James Robbins.
"We have every right to put these people on trial," Mr Ahmadinejad asserted.
"But I want to give them as a present to the British people to say they are all free."
He said they were being pardoned to mark both the Prophet Muhammad's birthday on 30 March, and the upcoming Easter holiday.
"I'm asking Mr Blair to not put these 15 personnel on trial because they admitted they came to Iranian territorial water," he added, referring to taped "confessions" made by the British sailors and marines.
Britain says the 15 were in Iraqi waters under a UN mandate when they were captured nearly two weeks ago. It says the confessions were extracted under duress.
"Unfortunately the British government was not even brave enough to tell their people the truth, that it made a mistake," Mr Ahmadinejad said.
The Iranian leader said no concessions had been made by the British government to secure the releases, but that Britain had pledged "that the incident would not be repeated".
'We respect Iran'
Prime Minister Tony Blair said Britain's approach to the crisis had been "firm but calm - not negotiating but not confronting either".
He did not thank or address the Iranian president, but said to the Iranian people: "We bear you no ill will. On the contrary, we respect Iran as an ancient civilisation, as a nation with a proud and dignified history.
"The disagreements we have with your government we wish to resolve peacefully through dialogue. I hope - as I've always hoped - that in the future we are able to do so."
The solution to the crisis - freeing the Britons while rewarding the Iranian commanders of the operation - appears to be a face-saving compromise, says the BBC's Frances Harrison in Tehran.
IRANIAN VERSION OF EVENTS
1 Royal Navy crew stray 0.5km inside Iranian waters
2 Iran gives set of co-ordinates to back up their claims
3 According to seized GPS equipment, the Royal Navy crew had previously entered Iranian waters at several other points
4 Iran informs Britain of the position where the crew were seized, inside Iranian waters
She says speculation is likely to continue over whether it had anything to do with developments in Iraq, where an Iranian envoy has reportedly been given access to five Iranians captured by US forces, and where a kidnapped diplomat was released on Tuesday.
Earlier on Wednesday Syria revealed that it had been mediating between Iran and the UK over the sailors and marines.
The family of one of the captives, Royal Marine Adam Sperry, hailed the announcement as "the best present imaginable".
"Whoever has been in the right or wrong, the whole thing has been a political mess, so let's just get them home," said his uncle, Ray Cooper.