BEIJING — China said Saturday its military seized a U.S. Navy unmanned underwater glider in the South China Sea to ensure the “safe navigation of passing ships,” but would give back the drone after determining it was an American device.

After the United States later confirmed it had “secured an understanding” for the return, seeming to settle one of the most serious incidents between the two militaries in years, President-elect Donald Trump tweeted that the U.S. should let China keep it.

Trump tweeted Saturday: “We should tell China that we don’t want the drone they stole back. – let them keep it!”

It was not immediately known what effect, if any, the president-elect’s tweet would have on the agreement with the Chinese.

The evening tweet was the second time the president-elect injected himself into the controversy through Twitter on Saturday.

Misspelling “unprecedented,” he tweeted Saturday morning: “China steals United States Navy research drone in international waters – rips it out of water and takes it to China in unpresidented act.” He later reissued the tweet, correcting the spelling.

Relations already were tense between the U.S. and China following Trump’s decision to talk by phone with Taiwanese President Tsai Ing-wen on Dec. 2. He later said he did not feel “bound by a one-China policy” regarding the status of Taiwan, unless the U.S. could gain trade or other benefits from China.

The USNS Bowditch is a Pathfinder class oceanographic survey ship. It is part of a 29-ship special mission that operates in the South China Sea. The 328-foot Bowditch has a crew of 24 civilians and 27 military personnel, according to the U.S. Navy Military Sealift Command website. U.S. Navy photo

The USNS Bowditch was in international waters Thursday afternoon and recovering two of the gliders when a Chinese ship approached, according to the Pentagon. The two vessels were within about 500 yards of each other at the time. U.S. Navy photo

China considers the self-governing island its own territory to be recovered by force if it deems necessary.

According to the Pentagon, the drone was seized Thursday while collecting unclassified scientific data in the South China Sea, which China claims virtually in its entirety.

The Pentagon said the drone was being operated by civilian contractors to conduct oceanic research. The U.S. lodged a formal diplomatic complaint and demanded the drone be returned.

Chinese Defense Ministry spokesman Yang Yujun issued a statement late Saturday saying that a Chinese navy lifeboat discovered an unknown device in the South China Sea on Thursday.

“In order to prevent this device from posing a danger to the safe navigation of passing ships and personnel, the Chinese lifeboat adopted a professional and responsible attitude in investigating and verifying the device,” Yang said.

The statement said that after verifying that the device was an American unmanned submerged device, “China decided to transfer it to the U.S. through appropriate means.”

The U.S. said that “through direct engagement with Chinese authorities, we have secured an understanding that the Chinese will return” the unmanned underwater vehicle, according to a statement from Peter Cook, spokesman for U.S. Defense Secretary Ash Carter.

The U.S. said China’s “unlawful seizure” came in international waters.

Yet China pointedly accused the U.S. of long sending ships “in China’s presence” to conduct “military surveying.”

“China is resolutely opposed to this and requests the U.S. stop such activities,” it said. “China will continue to maintain vigilance against the relevant U.S. activities and will take necessary measures to deal with them.”

Earlier Saturday, China’s foreign ministry said the country’s military was in contact with its American counterparts on “appropriately handling” the incident, though it offered no details on what discussions were underway.

The drone was seized while collecting unclassified scientific data about 57 miles northwest of Subic Bay near the Philippines in the South China Sea, which China claims virtually in its entirety, Navy Capt. Jeff Davis, a Pentagon spokesman, said Friday.

“It is ours. It’s clearly marked as ours. We would like it back, and we would like this not to happen again,” Davis told reporters. He said the drone costs about $150,000 and is largely commercial, off-the-shelf technology.

The USNS Bowditch, which is not a combat ship, was stopped in international waters Thursday afternoon and recovering two of the gliders when the Chinese ship approached, Davis said. The two vessels were within about 500 yards of each other. He said that the USNS Bowditch carries some small arms, but that no shots were fired.

According to the Pentagon, as the Chinese ship left with the drone, which is about 10 feet long, its only radio response to the U.S. vessel was, “We are returning to normal operations.”

Bonnie Glaser, senior adviser for Asia at the Center for Strategic and International Studies, said the seizure of the glider occurred inside the exclusive economic zone of the Philippines, not China, and appeared to be a violation of international law.

China delineates its South China Sea claims with a roughly drawn sea border known as the “nine-dash line” that runs along the west coast of the Philippines. However, it hasn’t explicitly said whether it considers those waters as sovereign territory, and says it doesn’t disrupt the passage of other nations’ shipping through the area. The U.S. doesn’t take a position on sovereignty claims, but insists on freedom of navigation, including the right of its naval vessels to conduct training and other operations in the sea.

Davis said that the incident could be the first time in recent history that China has taken a U.S. naval vessel. Some observers have called it the most significant dispute between the sides’ militaries since the April 2001 midair collision between a U.S. Navy surveillance aircraft and a Chinese fighter jet about 70 miles from China’s Hainan island that led to the death of a Chinese pilot.

There also have been increased tensions over Beijing’s ongoing military buildup in the South China Sea, mainly the development and militarization of man-made shoals and islands aimed at extending China’s reach in the strategically vital area, through which about $5 trillion in global trade passes annually.