A Turkish court on Friday freed an American pastor held for the last two years in Turkey, in a case that sparked a crisis in ties with the United States.
The court in the western town of Aliaga convicted Andrew Brunson on terror-related charges and sentenced him to three years, one month and 15 days in jail, an AFP correspondent said.
However, he was freed, taking into account time served and his good conduct during the trial, with the court lifting his house arrest and overseas travel ban, the correspondent said.
"This is the day our family has been praying for -- I am delighted to be on my way home to the United States," Brunson said in a statement.
The American Center for Law and Justice, a group that works on Christian legal cases and which represented Brunson, said he was set to return but had not yet left Turkey.
"It's been an extremely difficult time for our family and we want to express our appreciation to the millions of people around the world who have faithfully prayed for this day," Brunson said.
U.S. President Donald Trump, who has publicly pressed for Brunson's released, tweeted that he "will be home soon".
His Turkish lawyer Cem Halavurt earlier said the pastor was driven to his home in Izmir once the hearing was concluded.
Brunson's detention since 2016 caused not just one of the worst diplomatic rows of recent times between NATO allies Turkey and the U.S., but also led to a crash in the Turkish lira,which exposed the country's economic fragility.
Turkish judicial authorities repeatedly denied requests for the release of Brunson, who was moved from prison to house arrest in Izmir in July.
"I am an innocent man. I love Jesus. I love Turkey," he said in his final defence.
When the verdict was read out, Brunson wept and hugged his wife Norine.
U.S. broadcaster NBC said Turkey and the United States had reached a secret deal for Brunson to be released Friday and some charges against him dropped, in exchange for the U.S. easing "economic pressure" that included sanctions which have hammered the lira.
The resumption of the trial came at a sensitive time for the Turkish leadership, which is under global scrutiny over how it handles the case of Saudi journalist Jamal Khashoggi, who disappeared at Riyadh's consulate in Istanbul last week.
Both Turkish President Recep Tayyip Erdogan and Trump have pressed Saudi Arabia to explain what happened to Khashoggi.
If the Brunson issue is resolved to Washington's satisfaction, it could help the two sides coordinate their Saudi policy more closely.
Erdogan, who has in the past taken aim at Brunson, appeared to distance himself from the case in his latest comments, saying he could not interfere in judicial affairs.
"Whatever decision the judiciary makes, I am obliged to obey it," he told Turkish reporters.
Trump has lauded Brunson as a "great patriot" who was being held "hostage".
Brunson was first detained in October 2016 on allegations of assisting groups branded as terrorists as part of a crackdown by the Turkish government following a failed coup earlier that year blamed on U.S.-based preacher Fethullah Gulen.
He had faced up to 35 years in jail on charges of aiding terror groups and espionage. Prosecutors then demanded a sentence of up to 10 years.
He was convicted on charges of aiding terror groups while not being a member of them.
Brunson and U.S. officials insisted he is innocent of all charges.
Abdulkadir Selvi, a pro-government columnist in the Hurriyet newspaper whose columns are closely watched for indications of the Erdogan administration's thinking, wrote this week he expected the pastor to walk free and "solve" the Turkey-U.S. crisis.
The new hearing also came as Turkey braces for potential fines from U.S. authorities over Iran sanctions-busting by Turkish lender Halkbank, which has already seen the jailing of its deputy director general in the United States.
The U.S. is also watching the case of NASA scientist Serkan Golge, a dual U.S.-Turkish national, who was jailed for seven-and-a-half years in February on terror charges, a term reduced to five years last month.
Erdogan, who had a brief handshake with Trump on the sidelines of the annual U.N. General Assembly in September, has said he hoped to rebuild relations with Washington with the "spirit of strategic partnership."