While the Navy was staging war games and hunting down "enemy" submarines with sonar off the island of Kauai two summers ago, more than 150 lost and disoriented whales were swimming chaotically in the shallows of Hanalei Bay.

That mass stranding was a scene neither the Navy nor environmentalists want to see repeated as 40 ships from eight countries return to the islands this month for the world's largest international maritime war games.

But the two sides agree on little else, including whether sonar was to blame for that incident.

The continuing dispute highlights a deep divide over how to best protect marine mammals while safeguarding the nation's defenses.

This week, environmentalists won a temporary restraining order to stop the Navy from using a high-intensity sonar during this year's Rim of the Pacific 2006 exercise, which had scheduled sonar use to start Thursday.

The federal judge's order Monday came just days after the Defense Department granted the Navy a six-month exemption from certain federal laws protecting marine species to allow use of the "mid-frequency active sonar." Environmentalists had argued that the exemption was aimed at circumventing their lawsuit.

The Navy's failure to take a "hard look" at the environmental impact of war games was an "arbitrary and capricious" violation of the National Environmental Policy Act, U.S. District Judge Florence-Marie Cooper wrote in granting the restraining order.

Cooper ordered the two sides to meet to discuss mitigation measures in an effort to avoid further litigation. She also scheduled a hearing for July 18 on whether to replace the temporary restraining order with a preliminary injunction.

Government lawyers were reviewing the ruling and the Navy will probably respond soon, said Jon Yoshishige, a spokesman for the U.S. Pacific Fleet in Hawaii.

The Natural Resources Defense Council, the environmental group leading the legal battle, says whales have stranded and died on beaches around the world after being exposed to high-intensity, mid-frequency sonar. It says sonar can interfere with the ability of marine mammals to use their own underwater sounds to navigate, avoid predators, find food and care for their young.

Joel Reynolds, council senior attorney, said this shows the Navy has to be especially careful when it uses sonar in the biologically rich water around Hawaii.

"Whales and other marine life should not have to die for practice," Reynolds said. "Of course the Navy needs to train, and our lawsuit doesn't seek to prevent them from training. Our goal is simply to require them to incorporate a series of common-sense measures."

The military did not plan to use the sonar inside the national marine monument area that President Bush designated in early June in the waters off the Northwestern Hawaiian Islands. The sonar was to be used in waters surrounding only the main Hawaiian Islands, according to the Navy.

The Navy acknowledges sonar can hurt, even kill, whales, but it says many factors cause marine mammals to become stranded, including pollution, disease, starvation and collisions with ships.

The Navy also says it has been using sonar around the Hawaiian islands for a half century without marine mammal strandings attributable to the underwater noise.

Environmentalists point the stranding of more than 150 disoriented melon-headed whales in Hanalei Bay two summers ago while the U.S. Navy and its allies were using sonar in a nearby war game. An April report by the National Oceanic and Atmospheric Administration said naval sonar may have prompted the melon-headed whales, normally found in deep water, to seek refuge in Hanalei Bay.

The Navy says no evidence from that incident conclusively blames sonar.

Even so, the Navy had agreed to steps such as conducting aerial surveys for marine mammals before and after ships turn on their sonar and restricting sonar use to certain areas.

"We need to balance what we've got to do from the standpoint of military training and readiness and exercises with our commitment to environmental protections and safeguards," said Capt. Matt Brown, a spokesman for the U.S. Pacific Fleet.

The Navy says it must practice hunting submarines near the Hawaiian islands because that's the type of environment where it most likely will face an emerging threat: quiet, increasingly advanced submarines being bought or built by North Korea, Iran, China and other countries.

Adm. Gary Roughead, the U.S. Pacific Fleet commander, said the marine mammal protective measures would allow his sailors to learn and polish their skills while protecting the marine environment at the same time.

If the restrictions got much tighter, however, he said the Navy's ability to train its fleet would decline.

"They are perishable skills," Roughead said. "It's really an art form that you have to continue to practice."