Andrew Craig Brunson, an evangelical pastor from Black Mountain, North Carolina, arrives at his house in Izmir, Turkey. On Friday, a court in Turkey lifted the house arrest and travel ban against Brunson, who was arrested two years back on espionage and terrorism-related charges and whose detention triggered a diplomatic crisis with Washington. File picture: Emre Tazegul/AP Photo.

Izmir, Turkey - A court in Turkey on Friday lifted the house arrest and travel ban against US pastor Andrew Brunson, who was arrested two years back on espionage and terrorism-related charges and whose detention triggered a diplomatic crisis with Washington.

The court in the Aegean province of Izmir sentenced him to three years, one month and 15 days in prison, but he will be freed for time already served.

"My client is free now," Brunson's lawyer Ismail Cem Halavurt said after the ruling. He said he expects that Brunson will leave the country on Friday because there is a risk to his safety if he stays.

The trial against the evangelical US pastor triggered a diplomatic spat and trade row between NATO allies, Turkey and the United States.

Brunson had told the court: "I'm an innocent man. I demand my acquittal. I leave my defence to the lawyer. I love Jesus. I love Turks," according to state news agency Andolu.

Brunson was visibly shaken shortly before the verdict was announced. He wiped his eyes with a handkerchief, and then rested his forehead on the shoulder of his wife Norine and hugged her for several minutes.

The prosecutor had initially demanded 35 years in prison for the US preacher, who has lived in Turkey for more than two decades and has denied all the charges against him.

But on Friday, the prosecutor called for a sentence of up to 10 years on charges related to supporting a terrorist organization without being a member, according to Turkish media. He also asked for his house arrest and travel ban to be lifted.

Brunson was brought to the prison and court complex in Aliaga, near the western city of Izmir, under tight security, Anadolu reported. He wore a black suit and white shirt.

US media reported overnight that the White House had come to a "secret deal" with Ankara, in which Brunson would be released and some charges against him dropped in exchange for the easing of economic pressure on Turkey.

"We hope to have him safely back home soon!" US President Donald Trump wrote in response to the news on Twitter.

An earlier tweet indicated that his administration had worked hard on Brunson's case, but did not elaborate.

The case has strained relations between the US and Turkey, which have imposed tit-for-tat sanctions on each other's ministers, as well as tariffs on imports. The impasse has also triggered a currency crisis in Turkey.

The 50-year-old pastor from Black Mountain in the US state of North Carolina was detained in October 2016 and arrested that December.

He was accused of links to the movement of Fethullah Gulen, an Islamic cleric who lives in exile in the US and whom Turkey blames for a failed coup attempt on July 15, 2016.

Brunson was also accused of having ties to the outlawed Kurdistan Workers' Party (PKK), which is designated a terrorist organization by Turkey, the US and the European Union.

He came with his wife to Turkey in 1993 and eventually led the Izmir Resurrection Church.

Parishioners were among scores of people - many of them Turkish and international journalists - who flocked to the court.

Brunson is a "wonderful guy," one of them told dpa outside the court room. He helped refugees and always did the best that he could, said the man from Brazil, who has lived in Turkey for about 20 years.

"I admire him," said another follower, from New Zealand, adding that the US pastor has continuously helped people since he arrived in Turkey.

"He should get out," the New Zealander said. "It would be very painful for him to leave Turkey," he added, in the eventuality that Brunson's house arrest and travel ban is lifted.

Brunson's trial began in April and he was moved to house arrest in July after spending about a year and a half behind bars.