First nuclear crisis  

North Korean nuclear program goes back to 1952, the time of the Korean war, when Pyongyang decided to establish the Agency of nuclear energy. By the end of the 50's nuclear infrastructure was created with the help of the former Soviet Union. In the mid-60's Soviet model reactor was provided to the DPRK under control of the International Atomic Energy Agency (IAEA). Using the obtained technology, North Koreans secretly built their own 5 MW reactor at the Yongbyon experimental nuclear center, approximately 60 miles north of Pyongyang. In the 90's they could produce the is own plutonium for weapons. 
At that time nor Russia, now China could influence North Korea, because they established official relations with South Korea. Contrary, nor the US, nor Japan agreed to recognize the DPRK as a legitimate state.
Nuclear ambitions of Pyongyang caused concern of the IAEA, as it created a breach in the nuclear nonproliferation regime in the world. The agency, which had the DPRK as its member-state since 1985, insisted on inspections of the North Korean nuclear facilities. 
In the evening of December 18, 1991 ROK president Roh Tae-woo declared: "At this moment, there not a single nuclear weapon exists wheresoever in our country". In a nationally televised statement, president Roh also said, that since the moment North Korea did not have a reason not to clarify its nuclear program and to refuse accepting inspections from the IAEA. 
Making the atmosphere more favorable for Pyongyang, the United States and South Korea offered to cancel plans for the 1992 Team Spirit joint military exercise, which Pyongyang had considered 
as a rehearsal for a nuclear war on the Korean peninsula. 
On January 7, 1992, the DPRK said it would sign safeguards agreement with the IAEA and allow inspections in Yongbyon. Two weeks later, the first highest level US - North Korea meeting since the Korean war was held in New York on January 20 between undersecretary of state for political affairs Arnold Kanter and Korea Workers Party secretary Kim Yong Sun.
According to the report "Negotiating with North Korea: 1992–2007" by Robert Carlin and John W. Lewis, at the meeting North Korea indicated the strategic decision by Kim Il Sung to press for engagement with the United States and even accept a continuing US military presence on the peninsula as "a hedge against expanded, potentially hostile, Chinese or Russian influence". 
On February 19, 1992, Joint Declaration on the Denuclearization of the Korean Peninsula, signed by prime ministers of the DPRK and ROK in December, 1991, came into force. 
In 1992-1993 the IAEA conducted six inspections of seven declared North Korea's nuclear facilities. 
The international inspectors suspected that North Korea had reprocessed more plutonium, a key element in the making of nuclear weapons, than it had declared to the IAEA.
Pyongyang in reply said it did not believe that there was no nuclear weapons in South Korea and demanded inspections there as well. North Koreans insisted that as far as the nucs in the South was from USA, the issue should be negotiated between the DPRK and Washington. 
Nobody took it seriously until North Korea quit the Nuclear Nonproliferation Treaty on March 12, 1993.
In May 1993, the United Nations Security Council adopted a resolution, urging North Korea to honor its nonproliferation obligations. Pyongyang considered it as humiliation and conspiracy against the DPRK. 
The US administration of Bill Clinton started talks with North Korea, as it was expected by Pyongyang. The negotiations kicked off on June 2, 1993 in New York between the delegation of the DPRK headed by first vice minister of Foreign Affairs Kang Sok Ju and the American delegation led by assistant secretary of state Robert L. Gallucci. 
The US diplomats managed to convince Pyongyang to stay on NPT, at least temporarily. 
The two delegations issued a joined statement on June 11, assuring each other (1) against the threat and the use of force, including nuclear weapons. They also (2) agreed to principle of peace and security in a nuclear-free Korean peninsula, including impartial application of full-scope safeguards, mutual respect for each other’s sovereignty, and non-interference in each other’s internal affairs. Finally, the US and the DPRK expressed (3) their support of the peaceful reunification of Korea. 
Meanwhile, the US administration made some threatening statements related to the DPRK. When president Clinton visited the DMZ in Korea in July 1993 he reportedly warned that if North Korea developed and used an atomic weapon, the United States would "quickly and overwhelmingly retaliate". "It would mean the end of their country as they know it", - said Clinton. 
As Robert Galucci later told in an interview, one thing North Koreans "wanted then, and I think they still want, is more in the way of insurance that their security was not going to be threatened by the United States". 
The delegations of the two countries continued negotiations in Geneva between 14-19 July 1993, and the US agreed to support the North Korea's request to exchange closing of  
the 5-MW reprocessing plant at Yongbyon and the 50-MW to 200-MW reactors which were under construction for assistance in getting modern light-water reactors, which were less capable to produce nuclear weapons. 
The real crisis period was between May and June 1994. As Galucci recalled in the same interview, "we seemed to be headed more on a road to war than we did on a road to a negotiated end to the conflict".
The IAEA reported on May 19, 1994 that North Korea has begun removing 8,000 spent fuel rods from its nuclear research reactor in Yongbyon without permitting presence of international monitors. They needed to be able to tag these fuel elements, so they could then see where they would  come from in the reactor. 
On June, 13, North Korea announced its withdrawal from the IAEA. Rumors about a possible new war in Korea spread out across the country. The former American secretary of defense Willam Perry said in an interview: "We seriously considered solving the problem directly by simply striking the reactor and the processor at Yongbyon.. With conventional warhead - that could either be bombers or missiles". 
The ex-president of the United States Jimmy Carter went to Pyongyang to meet Kim Il Sung in June 1994. At that time, according to Galucci, there was a meeting of the National Security Council which the US president held in the Cabinet Room, attended by the secretary of state, secretary of defense, the vice president, chairman and Joint Chiefs of Staff. A telephone call came from Carter during the meeting, and Gallucci stepped out and listened to what the former president told. Jimmy Carter then described a possible way out of this situation and a deal that could be made with the North Koreans, the diplomat said. I was about a freeze by the North Koreans that guaranteed that there'd be no reprocessing, no separation of plutonium.  
The ex-president spent 4 days in Pyongyang. After that he was allowed to cross the demarcation line between South and North Korea to come to Seoul on June 18, 1994. Speaking to journalists at the American ambassador residence, Carter said that Kim Il Sung was ready for a dialogue with the US and South Korea, as well as was willing to freeze its nuclear program if the DPRK wold be helped to switch the nuclear program to light-water reactor technology. 
Kim Il Sung also asked the US and other countries to assure North Korea that they would not use nuclear weapons against it. 
Carter also negotiated a possible summit meeting between North and South Korea, and preparation was going smoothly and quickly as never before. 
President Clinton said on June 22, 1994, that the US was ready to start discussions with North Korea, and during these discussions, the United States would suspend efforts to pursue a sanctions resolution in the United Nations Security Council.  
A third round of U.S.-North Korean talks opened in Geneva on July 8. What happened next was a sudden death of Kim Il Sung.Dialog with North Korea was put off indefinitely. 
The US-North Korean talks resumed a month later and finally produced an "Agreed framework" of October 21, 1994.   
Under this agreement, the United States pledged to arrange the provision to the DPRK of two light water reactors with generating capacity of approximately 1,000 MW each by a target date of 2003. In exchange, North Korea promised to freeze and completely dismantle its graphite-moderated reactors and related facilities when the LWR project was completed. On the period of construction the LWR nuclear power plan it was agreed that alternative energy would be provided in the form of heavy oil for heating and electricity production. Deliveries of heavy oil had to reach a rate of 500,000 tons annually. 
The two sides decided to move toward full normalization of political and economic relations, first in the form of opening a liaison office in the other's capital following resolution of consular and other technical issues through expert level discussions, and later upgrade bilateral relations to the ambassadorial level. The American embassy was supposed to be opened in the premises of the diplomatic mission of the former GDR (East Germany). 
The Korean Peninsula Energy Development Organization (KEDO) was established 9 March 1995 by the US in agreement with South Korea, that was ready to cover half of the construction cost of LWR project in the DPRK if the reactors would be of the South Korean model. Seoul wanted to invest in the construction to engage with North Korea and also was looking at the perspective of national reunification, the future energy infrastructure of the united Korea. 
The contract was priced with a base value equivalent to $4.182 billion.  Japan and later the European Union joined the project and shared the expenses with South Korea. In Kumho, on the Eastern cost of North Korea, KEDO contractors has built foundations for the reactor's power block buildings, a breakwater and barge-docking facility, tetrapods for protection to the breakwater against ocean currents, a training center for operation and maintenance personnel and a simulator building. 
South Korea spent more than a billion dollars for the KEDO project, but the construction slowed down and finally was abandoned on the wave of political events around the Korean peninsula in the new millennium. KEDO also donated about $500 million in heavy fuel oil to North Korea for the period of 1995-2002. 
Soon after George Bush came to power in the US, he called North Korea a part of the "axis of evil" together with Iran and Iraq. When the war started in Iraq, the DPRK realized that it could be the next target. That made North Korea resume its nuclear program, and quit NPT in 2003. 
As Siegfried S. Hecker noted, the "Bush administration killed the Agreed Framework for domestic political reasons and because it suspected Pyongyang of cheating by covertly pursuing uranium enrichment". 
This was the beginning of the second nuclear crisis.