A Turkish court on Friday ruled in favor of releasing American Pastor Andrew Brunson nearly two years after Turkish authorities arrested him on charges of terrorism.

U.S. President Donald Trump’s administration had been advocating for Brunson’s release, arguing that the pastor is innocent. The Turkish government provided no concrete evidence tying Brunson to the two groups he allegedly aided – the Kurdistan Workers’ Party (PKK) and the Hizmet movement led by U.S.-based Islamic cleric Fethullah Gülen – and his defense has insisted that the real reason for his arrest was a growing interest on the part of the Turkish government to eradicate Christianity.

Trump wrote on Twitter before the court’s decision to release him, “My thoughts and prayers are with Pastor Brunson, and we hope to have him safely back home soon!”

My thoughts and prayers are with Pastor Brunson, and we hope to have him safely back home soon! — Donald J. Trump (@realDonaldTrump) October 12, 2018

Brunson’s detention has strained the relationship between NATO allies the United States and Turkey. The pastor, held since October 2016, was facing up to 35 years behind bars on charges of terrorism and espionage linked to the failed 2016 coup against Turkish President Recep Tayyip Erdogan’s government.

Brunson had been scheduled to appear in court on Friday.

Hurriyet Daily News reported:

After an eventful hearing [on Friday], the court sentenced Brunson to three years and one month in prison for aiding a terrorist organization, while ruling for his release from house arrest pending appeals procedures. The pastor is free to leave Turkey if he wants, as the court did not adopt a travel ban. The ruling was partly in line with the prosecution’s final case, which demanded the court to lift “precautionary judicial measures” while asking for a 10-year sentence. The flipping of key witnesses in the last hearing was seen as surprising by some observers, like the relatively softened stance of the prosecution … Brunson reiterated his innocence in the final hearing, asking the court to acquit him.

Brunson has already served more than two years in prison. In late July, Turkey placed him on house arrest for health reasons.

Turkey had officially charged the pastor with links to the PKK and Gülen, who lives in Pennsylvania in self-imposed exile. Turkish President Recep Tayyip Erdogan accuses Gülen of orchestrating the failed July 2016 coup in Turkey. Ankara has designated Gülen’s followers as terrorists.

Citing unnamed U.S. officials, NBC News reported on Thursday, ahead of the recent hearing, that the White House was expecting the Turkish government to release the pastor and return him to the U.S. “in the coming days.”

NBC noted:

Under an agreement senior Trump administration officials recently reached with Turkey, Brunson is supposed to be released after certain charges against him are dropped at his next court hearing, currently scheduled for Friday, the senior administration officials and a person briefed on the matter said. The details of the deal are unclear, but those familiar with the discussions said it includes a commitment by the U.S. to ease economic pressure on Turkey.

The Trump administration, which has maintained Brunson’s innocence, has already sanctioned two Turkish officials and doubled tariffs on Turkish steel and aluminum imports.

Trump administration has also been pushing for the release of other Americans detained by Turkey.

Turkish President Erdogan repeatedly said he would not interfere in the judiciary’s deliberations on Brunson.

“Whatever the judiciary decides on, I have to abide by that decision. Those who are involved with this also need to abide by the judiciary’s decision,” Erdogan reportedly declared on Tuesday.