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.

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

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".

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.