South Korea agreed Friday to give North Korea (search) 400,000 tons of rice after the two sides settled a dispute over a perceived threat from the communist North following recent U.S.-South Korean talks.

The two Koreas also agreed to connect their railways in mid-June inside the Demilitarized Zone (search) that has divided the Korean Peninsula for the past half century, according to a joint statement from the South Korean government.

The rival neighbors opened talks on economic cooperation Tuesday in Pyongyang (search), capital of North Korea, but the meeting immediately stalled after North Korean delegates criticized last week's summit between President Bush and South Korean President Roh Moo-hyun and warned of an "unspeakable disaster" for the South.

Setting aside economic issues, the Koreas haggled over the North Korean remark. The talks were initially scheduled to end on Thursday.

South Korea saw the remark as a threat and demanded an explanation. The North resisted and instead demanded that the South explain the "further steps" Bush and Roh had agreed to consider if North Korea increases tensions over its nuclear programs.

North Korea accuses the United States of planning an invasion, although Bush and Roh repeatedly have said they prefer a peaceful settlement.

The dispute ended Friday when chief North Korean delegate Pak Chang Ryon sought to ease South Korean ire.

By "unspeakable disaster," Pak said he meant that "the North and South should not bring disasters onto each other by intensifying confrontation," according to South Korean pool reports from Pyongyang.

The nuclear dispute flared in October, when U.S. officials said North Korea admitted it had a clandestine nuclear program. Washington and its allies are trying muster international pressure on Pyongyang to abandon its nuclear ambitions.

Friday's agreement also called for the two Koreas to begin building an industrial complex in North Korea next month to relocate textile, shoemaking and other labor-intensive factories from South Korea.

South Korea plans to provide the rice in four 100,000-ton batches and verify the aid is distributed to the needy.

North Korea suffers chronic food shortages and has depended on outside help since the mid-1990s to feed its 22 million people.

The Koreas were divided in 1945 and their border remains sealed.