THE HAGUE, Netherlands — The International Court of Justice ordered both Costa Rica and Nicaragua Tuesday to keep their military, police and civilian personnel out of a disputed border region along the San Juan river that separates them.

Costa Rica had asked the court to bar Nicaraguan troops from the disputed region and order it to halt dredging and tree felling from where the San Juan river empties into the Atlantic Ocean.

Nicaraguan President Daniel Ortega and his Costa Rican counterpart Laura Chinchilla said before Tuesday's hearing they would respect the ruling by the United Nations' highest judicial organ.

The court ordered both Costa Rican and Nicaraguan forces out, and told both countries to "refrain from any actions which might aggravate or extend the dispute."

Costa Rica went to the court last year claiming Nicaragua illegally sent troops and engineers into Costa Rican territory to dredge part of the river.

However, the judges refused to order Nicaragua to halt all dredging, saying it was not clear that the dredging "is creating irreparable risk of damage" to Costa Rica's environment.

Nicaragua praised the ruling, which only dealt with Costa Rica's request for emergency measures and not with the merits of the territorial dispute case.

"I think it is a very fair decision, Nicaragua is very happy with the result," said Managua's ambassador to the Netherlands, Carlos Arguello-Gomez.

Costa Rican Foreign Minister Rene Castro also welcomed the ruling and said the decision should allow the two countries to resume dialogue about the disputed region "step by step" as Nicaragua complies with the ruling.

He praised the judges for ruling that Costa Rica could send civilian staff to monitor any potential damage to internationally protected wetlands in parts of the disputed area.

At hearings in January, Nicaragua said it has long exercised sovereignty over the disputed stretch of river and was working to prevent it silting up.

"The river has been drying up," Arguello-Gomez said. "So our right to dredge it, which the court maintained, is very important."

Recent reports from the Costa Rican Foreign Ministry indicated that Nicaragua already has pulled its troops out of the area, which always has been uninhabited wetland. But the dredging work continues on the banks of the river.

The dispute drew in Google Inc. when the Nicaraguan official in charge of the dredging project said in a newspaper interview that he used Google's map system to decide where the work should be done.

Costa Rican Foreign Ministry legal adviser Sergio Ugalde told the court that Google quickly fixed an inaccurate map cited by Managua.

The river has long been a source of friction between Nicaragua and Costa Rica.

In 2009, the International Court of Justice set travel rules for the river, affirming freedom for Costa Rican craft to navigate the waterway while upholding Nicaragua's right to regulate traffic.