Ahmadinejad told a Tehran news conference he had pardoned the British personnel as a gift to the British people and to mark the birthday of Islam's Prophet Muhammad and Easter.
"I announce that the Iranian nation and the government of the Islamic republic -- while insisting on our power and right to try these military personnel -- have pardoned these 15 people, and we offer their freedom to the British people," he said.
Ahmadinejad said the British sailors and marines would be taken to Tehran airport immediately after the press conference. Britain welcomed the announcement and said it is seeking details on the timing and method of the release.
After the press conference, Iranian state television showed Ahmadinejad shaking hands and speaking with some of the Britons at the presidential palace. Iranian television now reports that the Britons will leave Iran on a plane on April 5.
Handing Out Medals
The Iranian leader made the surprise announcement at the end of a lengthy speech, during which he decorated the military officials responsible for the arrest of the British personnel.
"Here, as a representative of the great Iranian nation, I want to thank -- with a medal of third-degree bravery -- the courageous commander of those brave border guards who defended our borders and arrested the intruders," Ahmadinejad said as he presented the awards.
A few minutes before the announcement, Ahmadinejad said Iran will not allow anyone to violate its borders. He accused Britain of committing an "act of aggression."
"The beloved Iranian nation is displeased with the British military aggression against its territorial waters," he said.
Iran seized the Britons in the Persian Gulf on March 23 after accusing them of violating its territorial waters.
Britain says the group was carrying out routine antismuggling operations in Iraqi waters, but Iran says that their global positioning system (GPS) devices show they intruded in Iranian waters.
Criticism Of U.S. Iraq Policy
Ahmadinejad made the announcement at the end of a lengthy address, during which referred repeatedly to the Koran and the modern history of the Middle East.
He decried the U.S.-led invasion of Iraq in 2003 as based on the fallacy that the country had weapons of mass destruction. He said that although Iraq now had an elected government, "the occupation forces continue to stay there and people are still being killed."
Ahmadinejad's announcement came after Iran earlier welcomed a "change of tone" from London in the crisis over its seizure of 15 British sailors.
The British government on April 3 confirmed that it had direct contact with Iran's top security official, Ali Larijani, regarding the detainees, who were captured on March 23 in the Persian Gulf.
Today, Downing Street welcomed the Iranian announcement about the release of its sailors. White House spokesman Gordon Johndroe said President George W. Bush also welcomed the news of the release.
The crisis has come at a perilous time for Iran's relations with the West, with the United States refusing to rule out military action over the Iranian nuclear program and the United Nations imposing tough new sanctions.
But Bush said on April 3 in Washington that there would be no reciprocal release of the Iranian detainees in exchange for the release of the Britons. And today, the State Department said it was aware of no such connection.
In such situations, militarily strong Western nations such as Britain and the United States ordinarily bring a variety of diplomatic pressures to bear -- backed up with a remote, but real, threat of force, says James Phillips, who studies international security issues at the Heritage Foundation, a Washington policy-research center.
"The use of force is usually a last resort, but keeping it on the table strengthens diplomacy, which is the primary means of exerting pressure in cases like this," he says. "And, Britain and perhaps the U.S., but also Britain's other allies in NATO or the EU probably made it clear to Iran that this would have repercussions on a wide variety of diplomatic issues that would, in the long run, hurt Iran's national interest."
Phillips also cautions that the release may have been prompted as much by internal pressures in Iran. He said Iran's supreme leader, Ayatollah Ali Khamenei, occasionally reminds Ahmadinejad that as president, he is only of secondary importance in the country's political hierarchy.
In this case, Phillips says, Khamenei may seen the crisis over the captured Britons leading to a diplomatic disaster for Iran, so he may have ordered Ahmadinejad to release them.
Phillips says he takes the U.S. and British governments at their word that there is not connection between the status of the Iranians held in Iraq and the release of the British service members.
Oil prices fell after Ahmadinejad announced the release. Prices had risen steadily since Iranian forces detained the Britons. Oil prices had taken a downward turn before Ahmadinejad's announcement because of signs that a diplomatic solution to the crisis was imminent.
RFE/RL Iran Report
SUBSCRIBE For regular news and analysis on Iran by e-mail, subscribe to "RFE/RL Iran Report."