ALIAGA, Turkey — A Turkish court effectively freed American pastor Andrew Brunson on Friday after he spent nearly two years in jail and more time under house arrest on charges related to terrorism and espionage. Brunson had become entangled in a diplomatic dispute between Turkey and the United States and American officials had hoped that the fourth hearing in Turkey’s case against him would result in his release.

The court in the city of Aliaga found Brunson guilty and sentenced him to three years in prison, but released him on time served, based on a prosecutor’s recommendation. That move will allow him to leave the country.

Turkey’s government had faced threats of further U.S. sanctions over its treatment of the pastor, who denies all charges against him, but President Recep Tayyip Erdogan had insisted that the Turkish judicial system be allowed to proceed.

Friday’s hearing began in a prison complex near the western city of Izmir. Brunson arrived in a secured convoy before daybreak. The evangelical pastor was convicted by Turkey of terror-related charges and espionage, for which he had been facing up to 35 years in jail.

It was not immediately clear where or when Brunson would go next. His wife was at the court in Aliaga on Friday, too.

The pastor told the court on Friday that he is “an innocent man. I love Jesus, I love Turkey.”

Read more at CBS News.