Somali pirates who seized 10 hostages more than a month ago on a ship chartered by the U.N. World Food Program have agreed to release the vessel and crew, a spokeswoman for the organization said Saturday.

"An agreement has been reached for the release of the ship, crew and food in the next three days," the spokeswoman, Rene McGuffin, said in Nairobi, the Kenyan capital.

In the most high-profile of a recent spree of hijackings off the coast of lawless Somalia, the militiamen seized the MV Semlow on June 27 as it headed for the northern port of Bossaso carrying tons of rice donated by Japan and Germany.

Armed pirates often use speed boats to attack ships in the area and even targeted a laden oil tanker in one of nine incidents in recent weeks reported by the International Maritime Bureau, which maintains a Piracy Reporting Center in Malaysia.

In the World Food Program case, the pirates initially demanded a $500,000 ransom for the eight Kenyan crew members, Sri Lankan captain and Tanzanian engineer. They then reduced that to demand only the rice.

The World Food Program director for Somalia, Robert Hauser, diplomats and local leaders reached an agreement Friday at a meeting in Jowhar, where the new Somali government is based.

"We are tremendously grateful to the Somali Transitional Federal Government and the Kenyan ambassador for their combined efforts to ensure that the vessel, the food, and most importantly the 10-member crew who have suffered greatly during this ordeal will be released unconditionally," Hauser said.

Elders and community leaders speaking on behalf of the hijackers agreed to release the ship and discharge the rice in El Maan, a port north of the Somali capital, Mogadishu, for distribution in central regions, the WFP statement said. The ship would then return to its base in Mombasa, Kenya.

The Kenyan ambassador, Mohamed Abdi Affey, said the hijackers had wanted to take the rice to their area in the north but were satisfied with the agreement to distribute it in central Somalia.

"I'm very happy because we worked hard to get our nationals out. But it is not over until it's over," said Affey, who was joined by Sri Lankan and Tanzanian diplomats based in Kenya during several trips to Somalia to mediate the standoff.

The World Food Program said the handover of the rice to the Somali government, which relocated from the relative security of neighboring Kenya earlier this year, would be the first time the U.N. body and new administration had worked together on food distribution.

"WFP sent two shipments of food to Somalia in the last week to ensure that its operations in the country would continue and the hungry would not suffer because of the hijacking," it added.

Somalia has been synonymous with instability since warlords overran the country of approximately 8.6 million in 1991, carving it into fiefdoms after ousting dictator Mohamed Siad Barre.

The International Maritime Bureau classes waters off Somalia, located in the Horn of Africa, as some of the most dangerous in the world.

Among at least 25 attacks since the start of the year, the bureau reported an attack on a petroleum-product tanker on July 26 by a band of pirates in two speed boats armed with rocket propelled grenade launchers and machine guns. "It's very alarming, a considerable increase on the last quarter -- we are losing count," said Jayant Abhyankar, the bureau's deputy director.

The Jolly Marrone, an Italian cargo ship, escaped unscathed from a July 21 attack by pirates in Somali waters, the site of at least 25 incidents this year.