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. It was not clear when they might try to leave Iran.

The Germans — a reporter and a photographer for the mass-circulation tabloid Bild a.m. 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 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.

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.

“We hope to get them to the embassy in Tehran today,” said a ministry spokesman.

Iranian state TV confirmed the release, quoting Malek Ajdar Sharifi, the head of Justice Department of East Azerbaijan province, where the two Germans were jailed.

A spokeswoman for the journalists’ employer, Bild a.m. Sonntag, said the newspaper was aware they had been freed but could not comment further.

Iran’s state TV said German Foreign Minister Guido Westerwelle will arrive in Tehran later Saturday for discussions on “mutual ties and regional developments.” 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.