The 41-point agreement, which also calls for opening a hotline between the two militaries, marked another milestone in thawing relations between the two once-hostile countries. Their ties have dramatically warmed since a historic summit of their leaders in June.
"By resolving all related military issues, South and North have laid the most important foundation for the railway project," said a statement from Seoul's Defense Ministry.
After reports of the agreement, reached at a border crossing, South Korean officials said they were hopeful that the rail line could be reconnected by the fall, as scheduled.
If reconnected, the railway will become the first direct land transport link between the two Koreas since their 1950-53 war, which ended in an uneasy truce, not in a peace treaty. It will connect Seoul and Pyongyang, the two Korean capitals, and continue to Shinuiju, a major city on the North's border with China.
The Korean peninsula was partitioned into the communist North and pro-Western South in 1945.
It's believed there are more than a million mines in the demilitarized zone along the frontier including some 3,000 in the area where the road and railway are being rebuilt.
Also Thursday, in Pyongyang, the North's capital, economic officials of the two Koreas opened three days of talks on measures to help ease North Korea's chronic energy shortages.
However, those talks ended Thursday in a stalemate. They resume Friday.
In December, North Korea asked South Korea to provide 500,000 kilowatts of electricity. South Korea said it would consider the request after a joint survey of the North's energy shortages.
At Thursday's meeting, South Korean officials proposed that both sides jointly survey South Korea's energy situation as well as that of North Korea, said pool reports from South Korean reporters covering the meeting.
South Korean delegates specifically offered to visit one hydraulic and two thermal North Korean power plants during their stay in the North, which ends Saturday, the reports said.
North Korea has chronic and severe energy shortages, along with widespread food shortages that have forced the communist regime to rely on international aid to feed its 22 million people.
Travelers say power failures are common in the capital Pyongyang and much worse in rural areas, with many homes and workplaces without heat or electricity during the country's frigid winter.
Most of North Korea's aging Russian-made power plants are producing only about a third of their original capacity, South Korean officials say.
Among the points agreed to by the two countries Thursday regarding the railway and land mines was that no military installations can be built inside the so-called "north-south management zone." The only exception is a single uard post each in their sectors of the buffer zone, 250 yards from the border, or the military demarcation line.
Both Koreas already completed clearing all mines outside the buffer zone where the railway will be built. Mine-clearing inside the buffer zone is expected to begin this spring.
The two Koreas remain technically at war under a 1953 armed truce, but have begun to dismantle a half-century of Cold War confrontation since an historic summit meeting in Pyongyang last June between South Korean President Kim Dae-jung and North Korean leader Kim Jong-il.
©MMI Viacom Internet Services Inc. All Rights Reserved. This material may not be published, broadcast, rewritten, or redistributed. The Associated Press and Reuters Ltd. contributed to this report