Iran on Saturday freed two German journalists arrested four months ago after they interviewed the son of an Iranian woman sentenced to death by stoning for adultery.

An Iranian court threw out their 20-month prison sentence Saturday, commuting it to a fine of $50,000 each and clearing the way for their release, state media reports said. The newspaper they work for said it expected them to leave the country in the coming days, perhaps as early as Sunday.

The Germans -- a reporter and a photographer for the Berlin-based mass-circulation tabloid Bild am Sonntag -- got caught up in one of the many confrontations between Iran and the West, this one over the case of Sakineh Mohammadi Ashtiani. The mother of two has been convicted of adultery and sentenced to death by stoning, generating widespread international outrage.

Marcus Hellwig and Jens Koch were detained in October after interviewing Ashtiani's son in the northwestern city of Tabriz. Throughout their detention, Iranian officials accused them of a range of serious crimes from spying to having links to groups of Iranian exiles.

Ultimately, they were found guilty of committing acts against Iran's national security. State media reports on Saturday did not elaborate on the details of their alleged offenses.

Officials have also claimed they admitted to violating Iranian laws barring those entering the country on tourist visas from working as journalists.

In Saturday's ruling, a court in Tabriz said the Germans "deserved to have their punishment commuted and enjoy Islamic mercy," state TV reported.

Hours later in Berlin, Germany's Foreign Ministry said the two had been released and were in the care of German consular officials in Tabriz.

They flew to Tehran and were seen arriving at the capital's Mehrabad airport. The two men looked healthy.

Bild am Sonntag's deputy editor, Michael Backhaus, said the journalists had been brought to the German ambassador's residence in Tehran.

"We are all jubilant today," he told The Associated Press. "This is a 132-day-long nightmare that is now ending for the newspaper's staff and all relatives."

"We hope they'll be back in the coming days, maybe tomorrow or the day after tomorrow," he said.

Backhaus declined to discuss details of how the journalists' release had been achieved. He said diplomatic efforts were made continuously behind the scenes.

German Foreign Minister Guido Westerwelle was scheduled to arrive in Tehran later Saturday, officially for discussions on "mutual ties and regional developments," Iran's state TV said. He is likely to take the two Germans back home.

Ashtiani was convicted of adultery in 2006 after the murder of her husband and sentenced to death by stoning. In the face of international outrage, the sentence has been suspended and is under review by the Supreme Court.

She was later convicted of being an accessory to her husband's murder and sentenced to 10 years in prison. In the wake of the international outcry over the verdict, the Iranian government has been at pains to show that Ashtiani is guilty, airing several interviews with her repeatedly confessing her crimes.