The Stena Impero was seized by the Islamic Revolutionary Guard Corps in the Strait of Hormuz on 19 July, accused of violating international maritime law.
But this morning the vessel and its crew were heading for freedom after leaving the port of Bandar Abbas, on the southern coast of Iran.
The Foreign Office and the ship's Swedish owner Stena Bulk both welcomed the development, which comes amid heightened tensions between Iran and the West.
Stena Bulk said the crew were "safe and in high spirits" and free from Iranian waters as they headed to Dubai for medical checks.
Tehran comes in for criticism
Foreign secretary Dominic Raab continued his criticism of Tehran, saying: "The Stena Impero was unlawfully seized by Iran. It is part of a pattern of attempts to disrupt freedom of navigation.
"We are working with our international partners to protect shipping and uphold the international rule of law."
Stena Bulk's president and chief executive Erik Hanell confirmed the tanker and its crew had been released.
"The Stena Impero has now left Iranian waters and is en route to Dubai," he said.
"The captain has reported that all crew members are safe and in high spirits following release.
"Upon arrival, the crew will receive medical checks and debriefing by the company, following which arrangements have been made for them to return directly to their families in their respective countries."
Mr Hanell praised the crew for their "professionalism in the handling of this difficult and stressful situation", and pledged to support them and their families to aid their recovery.
Legal case ended
On Monday, Iranian government spokesman Ali Rabiei told journalists that legal proceedings against the Stena Impero had ended.
"Based on a friendly approach that allows forgiving mistakes, ground for freedom of the tanker has been paved and it can move," Mr Rabiei said.
The seizure came two weeks after Royal Marines were involved in an operation to seize a supertanker off Gibraltar.
The Iranian tanker, carrying £104 million worth of crude oil, was seized on suspicion of it breaking European Union sanctions on Syria.
Gibraltar later released the tanker, then called the Grace 1, after it said Iran had promised the ship would not go to Syria.
The ship seizures came after months of heightened tensions in the Persian Gulf, sparked by US President Donald Trump's decision to withdraw from Iran's nuclear deal last year.
Iran has since begun breaking the terms of the deal, which Prime Minister Boris Johnson described as "bad" in a change of UK policy, and called for a new accord to be brokered.