ISTANBUL (Reuters) - A U.S. Christian pastor on trial in Turkey on terrorism charges left prison on Wednesday after a court ruled he should be transferred to house arrest, a step that could help reduce tension between the NATO allies.

Andrew Brunson, who has worked in Turkey for more than 20 years and has been detained for the last 21 months, was escorted out of prison by officials in the coastal city of Izmir, live television footage showed. He departed in a convoy of cars.

Brunson, who is from North Carolina, was detained in October 2016 and charged with helping the group which Ankara says was behind a failed military coup earlier that year.

His lawyer Ismail Cem Halavurt said Brunson has to wear an electronic ankle bracelet and is banned from leaving the country.

The same court rejected a week ago a call by Brunson’s defence for his release. The state-owned Anadolu news agency said the court had decided, after re-evaluating the case, that he could leave prison on health grounds and because he would be under effective judicial control.

Brunson’s detention deepened a rift between NATO allies Washington and Ankara, who are also at odds over the Syrian war and Turkey’s plan to buy missile defences from Russia.

A source in the United States familiar with the developments said the sudden shift came a day before U.S. Vice President Mike Pence had been set to unveil a harsh new policy on Turkey.

The source, who was not authorised to speak publicly about the matter, said U.S. and Turkish officials had been working on a deal that would lead to Brunson’s release, with Washington expecting him to be freed at the trial last week.

U.S. officials had been under the impression that the deal was in place, the source said, adding that when Brunson was not released, Pence spoke with President Donald Trump and the two agreed harsh new policy measures were needed to force the issue.

Pence spoke by phone on Wednesday with Brunson, who expressed gratitude for the help from Trump and his top officials in securing his move from prison, the source said.

“LONG OVERDUE NEWS

Brunson was accused of helping supporters of Fethullah Gulen, the U.S.-based cleric who Turkish authorities say masterminded the coup attempt against President Tayyip Erdogan in which 250 people were killed. He was also charged with supporting outlawed PKK Kurdish militants.

The pastor, who denies the charges, faces up to 35 years in jail if found guilty.

Slideshow ( 4 images )

U.S. Secretary of State Mike Pompeo welcomed what he said was the “long overdue news” of Brunson’s transfer, but said it was 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,” he said on Twitter.

Financial markets took the transfer order as a positive, seeing in it the potential for improvement in ties between Ankara and Washington.

The Turkish lira TRYTOM=D3 strengthened to 4.8325 against the dollar from 4.8599 before the report. Shares of Halkbank, whose former deputy general manager was convicted in January of evading U.S. sanctions on Iran, jumped 12 percent.

Slideshow ( 4 images )

Erdogan has previously linked Brunson’s fate to that of the Muslim cleric Gulen, whose extradition from the United States has been a long-held demand of Turkish authorities. Gulen denies any involvement in the coup bid.

Trump said in a tweet last week that Brunson was being held hostage and that Erdogan should “do something to free this wonderful Christian husband & father”.

The U.S. Senate passed a bill last month including a measure that prohibits Turkey from buying F-35 Joint Strike Fighter jets because of Brunson’s imprisonment and Turkey’s purchase of Russia’s S-400 air defence system.