"Under the influence of the Muslim Prophet, [Iran] forgives these 15 people and gives their freedom to the British people as a gift," Ahmadinejad told a news conference on Wednesday.
"It is Iran's responsibility to find a quick solution"
Emkay, Auckland, New Zealand
Send us your views
Ahmadinejad also told the news conference that Britain was not "brave enough" to admit it had made a mistake in the standoff, which began when Tehran seized the 15 in the Shatt al-Arab waterway between Iraq and Iran on March 23.
The 15 were shown on Iranian television before their departure, celebrating and again apologising for entering Iranian waters.
Their release coincides with the release in Baghdad of an Iranian diplomat seized in early February.
Iran had blamed US forces for the abduction but the US denied involvement.
Iranian state media also said five Iranian officials captured by US forces in northern Iraq in January were expected to receive their first visit by an Iranian diplomat soon.
The British naval personnel, seized in the Gulf on March 23, have been held for 13 days.
Tony Blair, the British prime minister, welcomed the decision to free the personnel and thanked allies in Europe, the UN Security Council and the Middle East for their help.
He said Britain had taken "a measured approach, firm but calm, not negotiating but not confronting either" in the negotiations.
Blair also said the situation had opened up "new and interesting" lines of communication between Britain and Iran.
Iran also presented the release of the personnel as a diplomatic victory.
Ali Akbar Velayati, a former foreign minister and now advisor to supreme leader Ali Khamenei, said Britain sent a letter of apology to Iran theday before Ahmadinejad released the fourteen men and one woman.
"The Islamic Republic of Iran showed that it will defend its territorial integrity and has no fear," he added.
'Change of tone'
The decision to release the detainees came after Iran acknowledged a "change of tone" from Britain following talks between Ali Larijani, the secretary of Iran's Supreme National Security Council, and Nigel Sheinwald, Blair's chief foreign policy adviser, late on Tuesday.
Iran had insisted that they key to resolving the crisis was an admission from Britain that the sailors and marines did intrude into Iranian territorial waters when they were seized.
Britain maintains the group was carrying out routine anti-smuggling operations in Iraqi waters in line with a UN mandate, but Iran says the sailors' Global Positioning System (GPS) devices show they intruded into Iranian waters.