The two leaders reached agreement on a number of issues
South Korean President Roh Moo-hyun and the North's Kim Jong-il issued the declaration after a three-day historic summit in Pyongyang.
They called for international talks on a treaty to replace the armistice that ended the 1950-53 Korean War.
The agreement came a day after the North agreed to end its nuclear plans.
Officials involved in separate, international talks aimed at ending North Korea's nuclear programme confirmed that Pyongyang had committed to a timetable to disable its nuclear facilities.
'Permanent peace'
Mr Roh and Mr Kim shook hands and drank a toast after they signed the eight-point declaration.
South Korean media reported that I have diabetes and even heart disease, but the fact is that is not the case at all
Kim Jong-il
Health rumours denied Q&A;: Nuclear stand-off Korean media reaction
The agreement stated: "The South and North share the view that they should end the current armistice system and build up a permanent peace system."
It called for leaders of nations concerned to meet on the Korean Peninsula and agree an end to the 1950-1953 war.
Any such talks would probably involve the US and China which, along with North Korea, signed the armistice that ended the war.
South Korea did not sign and remains technically at war with the North.
The two sides also agreed to resume freight rail services across the heavily fortified border for the first time in more than five decades.
And the North Korean leader used the occasion to quash speculation that he was suffering from ill health.
THE TWO KOREAS 1910: Korean Peninsula colonised by Japan 1945: Divided into US-backed South and Soviet-backed North 1950-1953: Korean War, no peace deal signed 1987: North Korea bombs a South airliner, killing 115 1990s: South Korea introduces conciliatory Sunshine Policy 2000: Kim Jong-il and Kim Dae-jung hold first leaders' summit 2007: Kim Jong-il and Roh Moo-hyun hold second leaders' summit
In pictures: Summit end Outline of joint declaration History of the Korean War
"South Korean media reported that I have diabetes and even heart disease, but the fact is that is not the case at all," Mr Kim told delegates at the farewell luncheon.
Agreements were also reached on establishing a joint fishing zone in the disputed western sea border and on holding regular summits, although no timetable was given for these.
More reunions between families divided by the partitioning of the Korean Peninsula would be held, the declaration said.
The summit is only the second between leaders of the two nations.
The BBC's John Sudworth in Seoul says that, while there is a sense that history is being made, the detail of the declaration will be important.
A similar optimism surrounded the first summit seven years ago, attended by former South Korean leader Kim Dae-jung, but many people feel very little has really changed, our correspondent adds.
Nuclear deal
On Wednesday, officials involved in six-party talks on the North's nuclear ambitions revealed that Pyongyang had formally committed to disabling its Yongbyon reactor and related sites, and fully disclosing all aspects of its nuclear programme by the end of the year.
Yongbyon, the North's main reactor, was closed earlier this year in return for aid, as part of the first phase of the deal.
A US-led team of experts is to go to North Korea in the next two weeks to begin the process.
The final crucial phase of the deal - where North Korea surrenders its existing nuclear stockpile - is due to be implemented next year.
US President George W Bush has welcomed the agreement, but Japan - one of the six countries involved in the talks - remained cautious.
On Thursday its ruling party backed extending sanctions against North Korea, citing a lack of progress in a row over Japanese nationals abducted by Pyongyang.
North Korea carried out its first nuclear test in October 2006.
En una serie histórica de eventos, Kim Jong-il, el líder de Corea del Norte, y Roh Moo-hyun, el líder de Corea del Sur, han firmado la ''Declaración de Paz y Prosperidad'', una declaración de paz de ocho hojas; el tratado fue acordado dos días después de que los líderes se reunieran en una cumbre que comenzó el 2 de octubre.

"El Sur y el Norte compartieron la opinión de que deben terminar con el régimen actual del armisticio y establecer un régimen de paz permanente", decía el pacto que también declaraba que acordaban "cooperar estrechamente para poner fin a la hostilidad militar y para asegurar la paz y mitigación de la tensión en la península de Corea".

"Acordamos hacer un compromiso firme para llegar a la paz y prosperidad en la Península de Corea. Compartimos la necesidad de planear nuestras medidas para la paz coreana para el futuro", dijo Moo-hyun.

El pacto permite transporte de mercancías a través de la frontera, que había sido prohibido durante 50 años; también crea una operación conjunta para áreas disputadas del océano y propone un nuevo armisticio.

El tratado invita a todas las naciones "concernientes", particularmente Estados Unidos y China, a la Península de Corea para observar el fin de la guerra 1959–1953, también conocida como la Guerra de Corea. El pacto además establece que las dos naciones se reunirán en distintas cumbres regularmente.

Ambos líderes firmaron el pacto y estrecharon manos. Luego propusieron un brindis y bebieron por el acuerdo en una celebración. Esta es la segunda vez en la historia que los dos líderes se reúnen cara a cara.