A Turkish court has released Pastor Andrew Brunson after two years’ detention, leaving him free to return to the United States. The court declared him free to leave on Oct. 12.

Brunson, a 50-year-old member of the Evangelical Presbyterian Church, has lived in Turkey for over 20 years. He has led a small congregation in the city of Izmir.

The pastor, a native of North Carolina, spoke before the court decision, saying “I am an innocent man. I love Jesus. I love Turkey,” Reuters reports.

He had been detained for two years on terrorism and espionage-related charges. The charges concerned alleged links both with Kurdish militants and with backers of the imam Fethullah Gulen, whose movement Turkish authorities blame for a 2016 coup attempt.

Turkey is seeking Gulen’s extradition from the U.S., and Turkish president Recep Tayyip Erdogan once suggested Brunson be swapped with Gulen.

Both Brunson and U.S. officials said the charges against him were false. In July Turkish officials moved Brunson to house arrest for health reasons, and he lived at home with his wife Norine.

His cause had significant support from the Trump administration and other political leaders.

“I am overjoyed that Pastor Andrew Brunson is finally free from his cruel and unjust imprisonment and house arrest, and is coming home safely to the U.S.,” said U.S. Rep. Chris Smith (R-N.J.), who chairs the House Subcommittee on Global Human Rights and co-chairs the U.S. Helsinki Commission.

“For almost two years he was the victim of efforts by President Erdogan and the Turkish state to crack down on religious freedom as he languished in prison—and was then transferred to house arrest in July—on absurd charges of espionage and supporting a terrorist group, while his family suffered enormously,” Smith said.

Witnesses had told the court that testimony attributed to them was inaccurate.

The pastor was convicted in a Turkish court on Friday of aiding terrorism but instead of facing a sentence of three years or longer, he was sentenced to time served due to good behavior. The court ordered his immediate release.

U.S. officials said they had reached an agreement with Turkey’s government to secure his release.

Ismail Cem Halavurt, Brunson’s defense attorney, said the pastor was going to leave the country but added “I hope he is able to come back.”

“He is someone who absolutely loves Turkey,” he said, according to the Washington Post.

Halavurt said Brunson will spend two days in Germany before returning to the U.S.

Brunson’s case has been a priority of the Trump administration, which imposed sanctions on Turkey to try to secure his freedom. The diplomatic tensions over the pastor’s treatment have been blamed for a sell-off against the Turkish currency in international markets, which in turn worsened Turkey’s financial crisis.

Other U.S.-Turkey tensions include differences over Syria and Iran and the Turkish government’s planned purchase of military equipment from Russia.

His release comes ahead of the Nov. 6 mid-term elections, and white Evangelical Christians are a key part of the Republican base.

U.S. President Donald Trump mentioned the pastor several times on Twitter on Friday, finally announcing “PASTOR BRUNSON JUST RELEASED. WILL BE HOME SOON!”

Trump’s sentiments were echoed by Vice President Mike Pence.

“We thank God for answered prayers,” Pence said on Twitter Oct. 12. He praised the efforts of the U.S. State Department to help the pastor and his family.

Smith praised those who worked successfully for Brunson’s release.

“The United States must now hold the perpetrators of his unjust imprisonment accountable by maintaining and strengthening targeted sanctions on complicit Turkish officials,” he said.

U.S. officials had sought a release of Brunson that included others detained in Turkey: Serkan Golge, a Turkish-American scientist, as well as three Turkish citizens who had been employed at U.S. diplomatic missions, the New York Times reports.