Kim Jong-il, the North Korean leader who realized his family's dream of turning his starving country into a minor nuclear-weapons power even as the isolated nation sank further into despotism, died on Saturday of a heart attack, according to the country's state-run media.The North had kept news of the death of its leader secret for roughly two days, perhaps a sign that the leadership was struggling to position itself for what many believe could be a particularly perilous transition. A few hours after the announcement, the powerful Workers' Party and government officials released a joint statement suggesting Mr. Kim's chosen successor, his youngest son, Kim Jong-un, was in charge.The Workers' Party announcement said that "Under the leadership of our comrade Kim Jong-un, we have to turn sadness into strength and courage, and overcome today's difficulties."KCNA, the official news agency, said North Korean soldiers and citizens were swearing allegiance to Kim Jong-un. People on the streets of Pyongyang broke into tears as they learned of Mr. Kim's death, The Associated Press reported from Pyongyang.Kim Jong-un is believed to be in his late 20s and his youth and relative inexperience could make him vulnerable to power struggles; some analysts have questioned the depth of the military's support for him.Kim Jong-il's death came after a long illness, dating to 2008, that American intelligence agencies believed involved some form of a stroke. The North has indicated he was 69 years old, but scholars have said he could have been a year older."We took every emergency measure we could, but the great leader passed away," the North Korean statement said.His death ended 17 years of rule over the isolated, paranoid country that his father, Kim Il-sung, founded.American and Asian officials were on alert for any signs that the country, which has almost inexplicably avoided collapse in recent decades, could begin to fracture.South Korea put its military on alert, boosting surveillance along the 155-mile border, one of the world's most heavily armed frontiers, to detect any unusual signs from the North Korean military. American and South Korean officials have expressed concern that any power struggle could lead some factions in the North to lash out - as they did in 2010, attacking a South Korean island and, according to South Korean intelligence, sinking a warship. Fifty South Koreans died in the two separate episodes.Under Kim Jong-il's rule, the North accomplished the single milestone that his father had dreamed about, exploding two crude nuclear devices, one in 2006 and another in 2009, just months after President Obama took office. But while the tests - the first was a fizzle - may have given the country a measure of protection against an American invasion, which Mr. Kim and his military leaders long feared, they also deepened his isolation.The 2009 test killed any discussion inside the Obama White House of reaching out to the North Korean leadership, especially after Mr. Kim largely abandoned agreements he reached with the George W. Bush administration to denuclearize. Former Defense Secretary Robert M. Gates seemed to summarize the Obama administration's attitude toward the North when he declared that the United States would not provide aid to the country in return for its making new commitments to give up nuclear weapons."I don't want to buy the same horse twice," he said on repeated occasions. Only in recent months have the two sides had any significant contact, mostly over food aid.North Korea is estimated to have enough fuel to make at least eight nuclear weapons.Mr. Kim's death poses a moment of peril for both Washington, the North's nemesis, and Beijing, its last protector. "We're entering a period that is especially dangerous," said Jim Walsh, a professor at MIT's security studies programs who has met in recent months with several North Korean delegations as part of the behind-the-scenes, unofficial contacts from which the United States has gleaned some understanding of the power plays in Pyongyang. "Here is a young leader who may be distrusted by the military, and he has to prove himself," he said of Kim Jong-un. "And that can lead to miscalculation and inadvertent war."The White House, in a terse statement, said it was "closely monitoring reports that Kim Jong Il is dead. The President has been notified, and we are in close touch with our allies in South Korea and Japan."In a brief additional line, Mr. Obama's spokesman added: "We remain committed to stability on the Korean peninsula, and to the freedom and security of our allies." That seemed to be a soft warning to the North Koreans not to engage in any violence."There are a whole range of scenarios for when Kim dies," one former American military commander in South Korea said recently, insisting on anonymity because he was discussing classified American response plans. "Anyone who tells you they understand what is going to happen is either lying or deceiving himself."The Obama administration was engaged in urgent consultations with South Korean officials on Sunday evening. President Lee Myung-bak of South Korea and President Obama talked by telephone and agreed to closely cooperate in assessing the situation in North Korea, Mr. Lee's office said.The administration has done elaborate "war-gaming" on the repercussions of Mr. Kim's death, the official said, and that planning will now be put to the test.One area of concern is the potential for tension, or even military clashes, between the North and South during the leadership transition in Pyongyang. In 1994, after Kim Jong-il's father died, South Korea put its military forces on high alert, raising tensions.The United States had held meetings with North Korean diplomats, in what was viewed as a preliminary step toward possible multilateral talks over its nuclear program. But those contacts did not appear extensive enough to provide a channel of communication during this period.For now, the administration official said, the administration's top priority is on keeping a high-level dialogue with South Korea. Japan's foreign minister, Koichiro Genba, is in Washington on other business, and will meet Monday with Secretary of State Hillary Rodham Clinton.That session is now certain to be dominated by the death of Mr. Kim and how it would affect security in northeast Asia.Little is known about Kim Jong-un, Mr. Kim's third son. (The older two sons were considered too unpredictable or estranged to take over the country, according to American intelligence officials.) The youngest Mr. Kim has never met or dealt with world leaders. Until two years ago, the only picture the CIA had of him showed him in short pants at a school he briefly attended in Switzerland.He is believed by some intelligence officials to have been involved in planning the two attacks on the South in 2010, events that may have been intended to create his bona fides as a military leader.Unlike Kim Jong-il, his son has had little time to be groomed in the art of running a dysfunctional country of roughly 23 million people. Administration officials have said that they believe the younger Mr. Kim would have needed another year or so to solidify his position and win the full confidence of North Korea's military commanders.It is unclear whether, before his death, Kim Jong-il was able to establish any deep roots of allegiance for his son, especially at a time of widespread food shortages and international sanctions imposed for its nuclear weapons development.The son has recently taken key military and party posts, and elites have begun wearing buttons that suggest some loyalty to him. On Monday, his name topped a list of 232 party and military officials that made up a national funeral committee, which South Korean analysts say provided more evidence that he was in charge.There had been considerable speculation that the military might designate a so-called regent to run the country because of Mr. Kim's inexperience, but that did not appear to be happening, at least so far.The North declared a national mourning period from the day of Kim Jong-il's death until Dec. 29. It said Mr. Kim's body will be placed at the Kumsusan mausoleum in Pyongyang, where the body of his father, Kim Il-sung, lies in a glass case for viewing. The authorities will allow North Koreans to pay respects to Mr. Kim for a week starting on Tuesday, but said it would not receive foreign delegations.

An enormous funeral service is scheduled for December 28 in Pyongyang, according to KCNA, a state news agency. The following day, a separate "national meeting of mourning" will take place, with all North Koreans instructed to pay a three-minute silent tribute to Mr. Kim