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.

In a statement read by a tearful television announcer that was repeated by other state-run media, North Korea said Kim Jong-il had died of a heart attack while on his train, as he was conducting an “onsite guidance tour” in an unspecified part of the country. The statement said:

“We took every emergency measure we could, but the great leader passed away.” 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.