Ali Bagheri, the Iranian foreign ministry's spokesman for northern European affairs, said: "They were pardoned after requests from the Swedish authorities and their families, and after going through the legal process and to show goodwill."
Urban Ahlin, deputy head of the Swedish parliament's foreign affairs committee, was there to welcome the two men after visiting Iran three times in a bid to win the men's release.
"It is good for Iran and good for Sweden to show that dialogue is better and it is better not to be isolated. In the future Iranian and Swedish relations will improve," he said.
Their release comes less than two weeks after 15 British naval personnel held by Iran on accusations of illegally entering Iranian waters were suddenly pardoned and freed.
Two other Europeans, German tourist Donald Klein and French boat skipper Stephane Lherbier, were also both freed earlier this year before completing 18-month sentences for violating Iran's territorial waters.
Bagheri denied that the recent spate of releases were linked to growing pressure over Iran's nuclear programme.
"The Iranian approach to this matter is humanitarian and it is very evident and clear," he said, noting that Iran had also recently allowed a visit by the pair's families.
"There is no link on nuclear as the nuclear issue has its own path," he added.