ALIAGA, Turkey (CBSNEWS/AP) – A Turkish court 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 and one month in prison, but released him on time served, based on a prosecutor’s recommendation. That move allowed him to leave the country.

READ MORE: I-Team: Bank Of America And Zelle Customers Targeted In New High-Tech Scam

U.S. pastor Andrew Craig Brunson escorted by Turkish plain clothes police officers arrives at his house on July 25, 2018 in Izmir. (AFP/Getty Images)

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.

“We’re grateful to the president, members of Congress and diplomatic leaders who continued to put pressure on Turkey to secure the freedom of Pastor Brunson,” lawyer Jay Sekulow, who represents Brunson’s family, said in a statement received by the Reuters news agency. “The fact that he is now on a plane to the United States can only be viewed as a significant victory for Pastor Brunson and his family.”

READ MORE: Technology Helping Melissa ISD Retain School Bus Drivers During Nationwide Shortage

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

Friday’s hearing took place in a prison complex near the western city of Izmir. Brunson arrived in a secured convoy before daybreak. The evangelical pastor was convicted of terror-related charges, but he was also accused of espionage. Prosecutors had been seeking up to a 35-year sentence.

Brunson, 50, who has lived in Turkey for more than two decades, has always rejected the charges and strongly maintained his innocence. He is one of thousands caught up in a wide-scale government crackdown that followed a failed coup against the Turkish government in July 2016.

MORE NEWS: Parents Share Safety Concerns At Mansfield ISD Town Hall On Campus Security Following School Shooting