IZMIR, Turkey -- An American pastor flew out of Turkey on Friday after a Turkish court convicted him of terror links but freed him from house arrest. Andrew Brunson was being flown to the U.S. military hospital in Landstuhl, Germany, then on to Washington, where he is expected to meet with U.S. President Trump on Saturday.

The court near the western city of Izmir sentenced the North Carolina native to just over three years in prison for allegedly helping terror groups, but let him go because the 50-year-old evangelical pastor had already spent nearly two years in detention. An earlier charge of espionage was dropped.

The development removed a major irritant in fraught ties between two NATO allies still strained by disagreements over Syria, Iran and a host of other issues.

Get Breaking News Delivered to Your Inbox

"I love Jesus. I love Turkey," an emotional Brunson, who had maintained he was innocent of all charges, told the court during Friday's hearing. He tearfully hugged his wife Norine Lyn as he awaited the court decision.

He was later transported to Izmir's airport and was flown out of Turkey, where he had lived for more than two decades.

U.S. pastor Andrew Brunson and his wife Norrine arrive at the airport in Izmir, Turkey October 12, 2018. UMIT BEKTAS / REUTERS

"PASTOR BRUNSON JUST RELEASED. WILL BE HOME SOON!" Mr. Trump tweeted after the American was driven out of a Turkish prison in a convoy. After Brunson was airborne, Mr. Trump told reporters the pastor had "suffered greatly" but was in "very good shape," and that he would meet with him at the Oval Office on Saturday.

Brunson's release was a diplomatic triumph for Mr. Trump, who is counting on the support of evangelical Christians for Republican candidates ahead of congressional elections in November.

It could also benefit Turkey, allowing the government to focus on an escalating diplomatic crisis over Jamal Khashoggi, a Saudi contributor to The Washington Post who went missing more than a week ago and is feared dead after entering the Saudi consulate in Istanbul. Turkish officials suspect Khashoggi was killed in the consulate; Saudi officials deny it.

Additionally, Turkey could now hope that the U.S. will lift tariffs on Turkish steel and aluminum imports, injecting some confidence into an economy rattled by high inflation and a mountain of foreign currency debt.

Friday's ruling followed witness testimony that seemed to partly undermine the prosecutor's allegations and highlighted concerns that Turkey had been using the U.S. citizen as diplomatic leverage. Turkey bristled at suggestions that its judicial system is a foreign policy instrument, and has accused the U.S. of trying to bend Turkish courts to its will with tariffs in August that helped to send the Turkish currency into freefall.

Brunson's release doesn't resolve disagreements over U.S. support for Kurdish fighters in Syria, as well as a plan by Turkey to buy Russian missiles. Turkey is also frustrated by the refusal of the U.S. to extradite Fethullah Gulen, a Pennsylvania-based Muslim cleric accused by Turkey of engineering a 2016 coup attempt.

The court dropped an espionage charge against Brunson, who had faced up to 35 years in jail if convicted of all the charges against him. He was among tens of thousands of people, mostly Turks, who were caught up in a government crackdown after the failed coup.

He was accused of committing crimes on behalf of Gulen as well as Kurdish militants who have been fighting the Turkish state for decades.

Earlier, the court called two witnesses following tips from witness Levent Kalkan, who at the previous hearing had accused Brunson of aiding terror groups. The new witnesses did not confirm Kalkan's accusations. Another witness for the prosecution said she did not know Brunson.

Brunson again denied accusations that his church aided Kurdish militants, saying he had handed over a list of Syrian refugees whom the congregation had helped and adding that Turkish authorities would have identified any terrorists.

"We helped everyone, Kurds, Arabs, without showing any discrimination," he said.

The pastor, who is originally from Black Mountain, North Carolina, was imprisoned for nearly two years after being detained in October 2016. He was formally arrested in December of that year and placed under house arrest on July 25 for health reasons.

Turkish President Recep Tayyip Erdogan had resisted U.S. demands for Brunson's release, insisting that the courts are independent. But he had previously suggested a possible swap involving Brunson and Gulen, who denied he organized the coup attempt.

Other witnesses had not yet testified in Brunson's case and evidence was still not complete, suggesting a rushed effort to resolve the case.

Brunson led a small congregation in the Izmir Resurrection Church. The U.S. Commission on International Religious Freedom, with top representative Tony Perkins monitoring the trial, had listed him as a "prisoner of conscience."

While supporters in the United States celebrated Brunson's release, his case overshadowed the predicament of a Turkish-American scientist from NASA and several Turkish workers for the U.S. diplomatic mission who were arrested in Turkey.