A Chinese frigate and an unidentified foreign submerged submarine were spotted Thursday just outside Japanese territorial waters near the Senkaku Islands in the East China Sea, the Defense Ministry said, prompting Tokyo to protest to Beijing.

It is the first known time that a submerged foreign submarine has entered the contiguous zone, an area just outside Japanese waters around the Japan-controlled, China-claimed islands. The ministry believes the submarine is also from China.

A ministry official also said this was only the second confirmed instance of a Chinese frigate entering the contiguous zone around the Senkakus. The first was in June 2016.

After Japan protested, China justified the approach by claiming it has "full historical and legal basis for its sovereignty" over the islands, which it calls Diaoyu.

China's Defense Ministry expressed strong dissatisfaction with and firm opposition to the fact Japan had protested.

The friction comes despite all the recent positive developments between Asia's two biggest economies, with top political leaders from both sides agreeing to intensify efforts to improve relations.

Chinese Foreign Ministry spokesman Lu Kang, speaking at a press briefing in Beijing, said its navy was in the area as it had to follow and monitor activities of two vessels belonging to Japan's Maritime Self-Defense Force.

According to the Japanese Defense Ministry, the submarine was first detected Wednesday afternoon in a contiguous zone near Miyako Island elsewhere in Okinawa Prefecture.

It was spotted again on Thursday morning in the zone northeast of Taisho Island, part of the Japanese-administrated uninhabited Senkaku Islands, as was a Chinese Jiangkai 2-class frigate. Both vessels left the zone in the afternoon, the ministry said.

Japanese Vice Foreign Minister Shinsuke Sugiyama summoned Ambassador to Japan Cheng Yonghua to the Foreign Ministry and protested the frigate's entry into the zone, expressing "grave concern."

"This behavior unilaterally raises tensions, and we are seriously concerned about it," Defense Minister Itsunori Onodera told reporters.

The Japanese government's top spokesman, Chief Cabinet Secretary Yoshihide Suga, subsequently urged China "not to undermine the trend of improvement in Japan-China relations."

Although often strained over territorial and historical grievances, bilateral ties have recently shown signs of a thaw, with Japanese Prime Minister Shinzo Abe and Chinese President Xi Jinping agreeing late last year to make a "new start."

Japanese Foreign Minister Taro Kono is said to be planning a visit to China before the end of the month, which the Abe administration looks likely to try to handle as a separate matter from Thursday's maritime matter.

"(Kono) will thoroughly communicate Japan's stance on the Senkakus in a meeting with Foreign Minister Wang Yi," a senior Japanese Foreign Ministry official said.

Refraining from commenting on the nationality of the submarine, top spokesman Suga told a press conference the Japanese government will "act firmly and calmly to fully protect our territory on land, at sea and in the air."

He also said it is important that a bilateral communication mechanism for averting accidental clashes in the East China Sea be put into operation soon.

The mechanism has been subject to a decade of negotiations. Japanese and Chinese officials discussed the hotline at a meeting in Shanghai last month, and sources close to bilateral relations said afterward both sides have largely agreed on how to implement it.

The last time a submerged foreign submarine was seen anywhere in Japanese contiguous waters was in February 2016.

The contiguous zone is defined as being within 24 nautical miles of shore, while Japanese territorial waters are within 12 nautical miles from shore. The sailings into the contiguous zone do not present a problem under international law.

China Coast Guard vessels have frequently entered territorial waters around the Senkakus as part of China's claim to the islets.

Kenji Kanasugi, director general of the Japanese Foreign Ministry's Asian and Oceanian Affairs Bureau, also lodged a separate protest with senior officials at the Chinese Embassy in Tokyo, according to a senior Foreign Ministry official.

The Japanese government purchased most of the Senkaku Islands from a private Japanese owner in 2012, putting them under state control. The development prompted sharp criticism from China and triggered frequent intrusions by China Coast Guard vessels into Japanese waters around the islets.

In November 2004, a Chinese nuclear-powered submarine entered Japanese territorial waters around other islands in Okinawa Prefecture.

That intrusion prompted the Japanese government to order the MSDF to take security action. But no such order was issued this time, with the submarine remaining outside territorial waters.

China wants to avoid an unintended clash at sea just as much as Japan does, an international political analyst said, because it would invite trouble with the United States, Japan's defense ally.