China has freed a Japanese scholar who it claimed was spying during a visit to the country earlier this year, the two governments said Friday.

Neither Japan nor China said why Nobu Iwatani, a professor at Hokkaido University, was released. But diplomatic sources said Beijing apparently hopes the release will lay the groundwork for a planned trip to Japan by President Xi Jinping next spring.

Iwatani returned home in good health on Friday, according to the Japanese government.

"Since Hokkaido University Professor Iwatani was detained, the government has been calling for his early return to Japan at every (diplomatic) level," Prime Minister Shinzo Abe said at his office.

"We are truly grateful that Professor Iwatani returned home safely and was reunited with his family," Abe told reporters.

The Chinese Foreign Ministry said Iwatani confessed to illegally collecting state secrets in violation of China's criminal and counterespionage laws.

Iwatani expressed repentance and was granted bail, ministry spokesman Geng Shuang said at a press briefing in Beijing.

The professor once worked for the National Institute for Defense Studies in the Japanese Defense Ministry.

The release came amid a recent thaw in Sino-Japanese relations long frayed over wartime history and territory.

(Chinese Foreign Ministry spokesman Geng Shuang speaks at a press briefing in Beijing on Nov. 15, 2019.)

Japan and China now see their relations as "on a normal track" and are making arrangements for Xi's planned trip to Japan.

China has been stepping up its watch over foreign organizations and individuals in the name of protecting national security since Xi came to power in 2013.

Abe told Chinese Vice President Wang Qishan, a close aide to Xi, during their meeting in Tokyo last month to handle the case of the Japanese professor in a "positive manner," effectively calling for his release.

Abe filed a similar request in separate talks with Premier Li Keqiang on Nov. 4 on the sidelines of a regional summit in Thailand.

According to Geng, Chinese national security authorities on Sept. 8 seized materials related to Chinese state secrets at a hotel where Iwatani was staying.

The scholar has admitted to collecting secrets in the past as well, Geng said, adding that Iwatani left China for Japan on Friday.

Speaking to reporters in Tokyo, Foreign Minister Toshimitsu Motegi said the professor's detention was one of the issues of bilateral concern that Japan wanted to resolve to create a "good environment" to receive Xi.

Tokyo plans to push for early releases of other Japanese nationals Beijing has detained, according to Japanese officials.