ALIAGA, Turkey (Reuters) - A Turkish court ruled on Friday to release the U.S. evangelical Christian pastor at the center of a bitter diplomatic row between Ankara and Washington, a move that could be the first step toward mending ties between the NATO allies.

The court passed a 3 years and 1-1/2 month sentence on Andrew Brunson, who had been charged with terrorism offences, but said he would not serve any further time because he had already been detained since October 2016.

Witnesses said Brunson wept as the decision was announced. Before the judge’s ruling, the pastor told the court: “I am an innocent man. I love Jesus, I love Turkey.”

The case against Brunson, an evangelical preacher from North Carolina who has lived in Turkey for more than 20 years and was arrested two years ago, had led to U.S. tariffs against Turkey and drawn condemnation from President Donald Trump.

Chris McGrath via Getty Images Turkish soldiers stand guard outside the entrance to Aliaga Prison Court after American pastor Andrew Brunson arrived ahead of his court hearing on October 12, 2018 in Izmir, Turkey.

Brunson was charged with links to Kurdish militants and supporters of Fethullah Gulen, the cleric blamed by Turkey for a failed coup attempt in 2016. Brunson denied the accusation and Washington had demanded his immediate release.

Earlier, witnesses told the court that testimonies attributed to them against the pastor were inaccurate, heightening expectations that Brunson could be released and returned to the United States.

Brunson appeared in the courtroom in the western coastal town of Aliaga wearing a black suit, white shirt and red tie. His wife Norine looked on from the visitors’ seating area as he listened to testimony from defense and prosecution witnesses.

“I do not understand how this is related to me,” Brunson said after the judge questioned one of a series of witnesses. He said the judge was asking the witness about incidents Brunson was not involved in.

The lira was little changed on the day. It had firmed 3 percent on Thursday on expectations that he would be released. It stood at 5.910 at 1336 GMT.