(Bloomberg) -- A Turkish court set free U.S. Pastor Andrew Brunson after holding him in prison for almost two years, removing a key source of tension between Turkey and the United States.

The court in Izmir convicted Brunson, an evangelical pastor from North Carolina, and sentenced him to three years, 1 month and 15 days in jail, but lifted all judicial controls and released him after accounting for penalty reductions and time served.

Brunson had been accused of collaborating with terrorist groups and participating in a 2016 coup attempt in Turkey. His prolonged imprisonment led the U.S. to impose sanctions on two Turkish ministers and threaten further penalties were he not released.

The lira reversed a gain to a loss after the decision, trading 0.5 percent lower at 5.9511 per dollar as of 4:40 p.m. in Istanbul.

To contact the reporters on this story: Cagan Koc in Istanbul at ckoc2@bloomberg.net;Onur Ant in Ankara at oant@bloomberg.net

To contact the editor responsible for this story: Benjamin Harvey at bharvey11@bloomberg.net

©2018 Bloomberg L.P.