WASHINGTON — Five Chinese Navy ships that sailed this week off the coast of Alaska entered United States territorial waters, but they have since left the area, Pentagon officials said on Friday.

Capt. Jeff Davis, a Defense Department spokesman, said that at one point the ships had come within 12 nautical miles of the United States, which put them inside American territorial waters. But Captain Davis said that it was a “legal transit’’ of the ships in the Bering Sea and that the Chinese had complied with international law.

Defense officials said that this was the first time that the American military had noted such activity by China. The ships’ arrival in the area came as President Obama was touring Alaska.

The Chinese venture into waters off the Alaskan coast occurred as China has increasingly been flexing its military muscle, particularly in waters off the coast of China. Beijing has increased military spending and now has an aircraft carrier, the Liaoning.