A court in Turkey has freed a US pastor from house arrest in a case that badly strained ties between the US and Turkey.
Andrew Brunson was arrested over alleged links to political groups, including the banned Gulenist movement, after a failed coup attempt in 2016.
The court convicted him of terror-related charges and sentenced him to three years in jail.
But Mr Brunson was released because of the time he had already been detained.
Additional charges of espionage were dropped.
"This is the day our family has been praying for, I am delighted to be on my way home to the United States," Mr Brunson said in a statement.
"My entire family thanks the president, the administration, and Congress for their unwavering support," he added.
The Reuters news agency reported that the pastor would be flown back to the US on a military aircraft.
What was he accused of?
Mr Brunson has lived in Turkey with his wife and three children for more than 20 years, most of it working for the small Izmir Resurrection Church, which had a congregation of about two dozen people.
He was arrested in October 2016. The authorities accused him of having links with the outlawed Kurdistan Workers' Party (PKK) and the Gulenist movement, which Turkey blames for the 2016 failed coup. He also faced up to 35 years in jail on charges of espionage.
In July 2018 he was released from prison for health reasons and moved to house arrest until his trial. A few weeks later, the US imposed sanctions on Turkey's justice and interior ministers over his continued detention.
Mr Brunson and US officials insisted he is innocent of all charges.
Ahead of the court's decision, US broadcaster NBC reported that Turkey and the US had reached a secret deal for Mr Brunson to be released in exchange for the US easing sanctions.
What happened in court?
Dressed in a black suit, white shirt and red tie, Mr Brunson, who was one of 20 Americans charged after the coup attempt two years ago, told the court he was "an innocent man".
"I love Jesus. I love Turkey," he said.
The pastor was convicted on charges of aiding terror groups while not being a member of them, and sentenced to three years in prison. The court took into account the time he had already spent in detention, lifting his house arrest and overseas travel ban.
When the verdict was read out, he wept and hugged his wife Norine.
'Pressure was too much'
By Mark Lowen, BBC Turkey Correspondent
President Recep Tayyip Erdogan has always insisted that he could not meddle with Turkey's judicial independence and that only the courts would decide Pastor Brunson's fate. But the World Economic Forum places Turkey 103rd of 137 countries in the independent judiciary rankings and Turkey-watchers knew it would always come down to a political decision.
In the end, pressure from Washington on Ankara was too much. Sanctions, trade tariffs and the threat of more had led US-Turkey relations to nosedive - and with them, the Turkish lira. Facing spiralling inflation, a 40% drop in the value of the currency and the start of an economic crisis, Turkey had to act to normalise relations with the US. Mr Brunson was the key.
Andrew Brunson had the American government behind him. Deniz Yucel, the former correspondent of Die Welt, who was imprisoned and then finally freed in Turkey, had the German government supporting him. Tens of thousands of others here who claim wrongful imprisonment don't have the backing of a powerful state to resist what they say is Turkey's politicised judiciary.
Why is it significant?
Pastor Brunson's detention has soured relations between Washington and Ankara, who are allies in Nato, with both sides imposing sanctions on the other.
President Recep Tayyip blames Muslim cleric Fethullah Gulen for the attempted coup but Mr Gulen, who is based in Pennsylvania, denies any involvement.
Turkey wants the US to agree to his extradition. US support for Kurdish forces fighting the Syrian civil war has also angered Mr Erdogan, who views them as an extension of the PKK.
The PKK - a Turkish-Kurdish rebel group fighting for autonomy since the 1980s - is considered a terrorist group by Turkey and the US.
PASTOR BRUNSON JUST RELEASED. WILL BE HOME SOON!— Donald J. Trump (@realDonaldTrump) October 12, 2018
But in recent weeks, Mr Erdogan said he hoped to rebuild relations with Washington with the "spirit of strategic partnership".
More than 50,000 people were arrested in Turkey in President Erdogan's huge post-coup crackdown.