The move could pave the way for the first train services between the Cold War rivals for more than five decades.
"The North and South will carry out test runs ... on May 25," read an agreement between officials from the two countries at a meeting in the North Korean city of Kaesong that wrapped up early on Saturday.
South Korea's unification ministry officials said a South Korean train carrying about 100 people would test the Seoul-Shinuiju line that links the two capitals.
The train will run on 27.3 km (17 miles) of newly laid track from the South's border city of Munsan to the North's Kaesong.
A similar number of people will travel in the opposite direction on a 25.5 km stretch from North Korea's Mount Kumgang to South Korea's Jejin Port on the eastern coast.
"South Korea is like an island as it is cut off from the continent by the division. Opening the cross-border railways would link us to the continent by land," Yang Chang-Seok, a unification ministry spokesman, told journalists.
Route to Europe
South Korea hopes the railways could be linked to Russia's Trans-Siberian railroad and allow an overland route connecting the Korean peninsula to Europe. Such a route would cut delivery times for freight, which now travels by sea.
The agreement came ahead of a planned trip to Pyongyang by a former president of the South, Kim Dae-Jung.
Kim Dae-Jung has said he wants to travel by train when he heads north for his second meeting in six years with North Korean leader Kim Jong-Il in mid-June to discuss reconciliation.
Kim Jong Il and the South's leader
agreed to the project in 2000 (file)
The agreement, which is part of a series of reconciliation projects between the two Koreas, comes with the Stalinist North refusing to defuse a stand-off with the United States over its nuclear weapons programme.
The linkage of inter-Korean railways and roads was the first project to be pursued after Kim Dae-Jung and Kim Jong-Il met in 2000.
The test runs, which the two sides had initially agreed to carry out in October 2004, have been put off for political and technical reasons.
As the railways pass through the sensitive border, a separate military agreement on safe passages is required. Military officials of the two Koreas will tackle this issue when they meet next week.
Two road links running parallel with the railways have been restored and are used for business and sightseeing in the North.