Image copyright AFP/Getty Image caption US pastor Andrew Brunson cannot leave the country and must wear an ankle bracelet

A US pastor detained in Turkey for almost two years is to leave prison and move to house arrest until his trial, a court has ruled.

Andrew Brunson was arrested in October 2016 for aiding an organisation led by exiled preacher Fethullah Gulen - which Turkey regards as a terrorist group.

Turkey blames Mr Gulen for a failed coup attempt against President Recep Tayyip Erdogan that year.

The pastor faces 35 years in prison if found guilty of the charges.

State media report that almost all the evidence for the case has been collected.

US Secretary of State Mike Pompeo welcomed the decision, but said on Twitter that it was "not enough" and that there was "no credible evidence" against the pastor.

Skip Twitter post by @SecPompeo We welcome long overdue news that Pastor Brunson has been moved from prison to house arrest in #Turkey, but it is not enough. We have seen no credible evidence against Mr. Brunson, and call on Turkish authorities to resolve his case immediately in a transparent and fair manner. pic.twitter.com/So2A4hfinZ — Secretary Pompeo (@SecPompeo) July 25, 2018 Report

Turkey's case against Mr Brunson has strained relations with its Nato allies and drawn fire from US President Donald Trump.

Skip Twitter post by @realDonaldTrump A total disgrace that Turkey will not release a respected U.S. Pastor, Andrew Brunson, from prison. He has been held hostage far too long. @RT_Erdogan should do something to free this wonderful Christian husband & father. He has done nothing wrong, and his family needs him! — Donald J. Trump (@realDonaldTrump) July 19, 2018 Report

US support for Kurdish forces fighting the Syrian civil war and its refusal to extradite Mr Gulen have angered President Erdogan, while Turkey's decision last year to buy Russian anti-aircraft missiles drew controversy.

State media say the court in the western city of Izmir decided that he should be released on health grounds.

Cem Halavurt, a lawyer for Mr Brunson, confirmed he was to be placed under house arrest, and would have to wear an electronic ankle bracelet.

He called the charges against his client "totally unfounded".

Image copyright Reuters Image caption Cem Halavurt confirmed his client was to be moved to house arrest

Mr Brunon has lived in Turkey for 23 years and worked as a Protestant pastor at the Izmir Resurrection Church.

He became one of more than 50,000 people arrested as part of President Erdogan's huge crackdown following the coup attempt.

Prosecutors say Mr Brunson worked with a group led by Mr Gulen, who is living in exile in Pennsylvania, as well as with the Kurdistan Workers' Party (PKK).

Mr Gulen has denied any involvement in the attempted coup. The European Union has said it does not share Turkey's view that his network is a terror organisation.