ISTANBUL — An American former NASA scientist sentenced in Turkey to over seven years in prison on terrorism charges was suddenly freed Wednesday evening, without explanation, hours after a phone call between the presidents of Turkey and the United States.

The scientist, Serkan Golge, 39, is a Turkish-American citizen who was arrested while on vacation visiting his family in southern Turkey in 2016, in the aftermath of a coup attempt that failed to oust President Recep Tayyip Erdogan.

Mr. Golge’s wife, Kubra Golge, confirmed by telephone that he had just walked free from prison and was heading back with his parents to their home in the southern city of Hatay.

“I just talked to him on the phone. He is going back to his family,” she said. “He was shocked.”

“He said ‘I am very thankful I am out of prison. I am very happy.’ And I cried,” she said.