The troops exchanged intensive fire with the militants who were believed to be holding as many as 1,200 hostages without food or water, while agonised relations screamed for their loved ones.
"They are alive! They are alive! They are alive!" yelled rescuers to parents as they carried out wounded and shocked children.
US President George W. Bush, speaking just a week ahead of the third anniversary of the September 11 attacks on the US, denounced the hostage-taking as "another grim reminder" of terrorist tactics.
"We mourn the innocent lives that have been lost. We stand with the people of Russia. We send them our prayers in this terrible situation," he said, leading world outrage at the carnage.
After hours of chaos and confusion, authorities finally said they had identified the bodies of 79 victims after the siege. But Interfax news agency, quoting its correspondent on the scene, said more than 100 corpses of hostages were found in the school gymnasium where they had been held.
"There was a bomb taped to the ceiling. The tape peeled off, the bomb fell and exploded," a young teenage girl told Russian television after escaping.
Hostages fleeing into the arms of waiting troops shielding behind armoured personnel carriers gratefully guzzled down bottles of water. "We drank urine," one naked boy said.
"There were pieces of burned corpses in the gymnsasium, skulls. Impossible to identify. The roof caved in and the tiles were covering the bodies," wrote a correspondent for the online newspaper Gazeta.ru.
After hours of running battles with the hostage-takers, a senior Russian army general told the NTV television network after nightfall that operations had been completed.
"Almost all of the bandits were killed and several have been arrested," said General Viktor Sobolev, commander of the 58th army based in the northern Caucasus. "It is unlikely that any got away."
But ITAR-TASS news agency reported that four militants were still at large, while eight had been killed and three arrested. Security officials earlier said 10 of the 20 militants killed in shoot-out were of Arab descent.
Amid total panic and confusion, soldiers were seen stretching away the injured, while some of the freed hostages sat numbly or in tears on rows of green canvas stretchers lined up on some grass across the road from the school.
Security service officials said that some 556 local residents and former hostages were taken to hospital. Among them were 332 injured children.
Six children were in serious condition, an AFP correspondent on the scene reported, and Interfax said the bodies of 17 others were seen outside the local hospital morgue.
Russian President Vladimir Putin had vowed the hostages' safety was his top priority and the security services said the sudden assault on the school had not been planned.
"I want to point out that we had not planned any kind of armed action. We offered the continuation of the ongoing talks to peacefully release the hostages," said Andreyev.
He said the chain of events was triggered when two powerful explosions went off around the school building at around 1:00 pm (0900 GMT).
"The bandits opened intensive fire at the fleeing adults and children. To preserve the lives of the hostages, fire was opened in reply on the bandits," Andreyev said.
The gunmen had reportedly mined the school's grounds, and at one point threatened to kill 50 children for every one of their number killed.
Separatists have been waging a decade-long war for independence from Russian rule in Chechnya, where on Sunday the Kremlin-backed candidate won presidential polls widely condemned as neither free nor fair.
European leaders called the bloody outcome of the crisis a "deep human tragedy," but accepted the "dilemma" facing the Russian authorities.
UN Secretary General Kofi Annan was also "horrified to learn that a large number of children and others have lost their lives or were injured during the last few hours," a spokesman said.
But there was also some anger at the actions of the special forces.
Polish Prime Minister Marek Belka said he was "shocked and outraged" by the assault on the school by the Russian forces.
"I never imagined that an anti-terrorist unit could go so far. All the limits have been over-stepped. It's impossible to go any further," he said.
Figures of the number of hostages had varied since the start of the crisis. "There may have been 1,200 hostages, 70 percent of them children," Kremlin aide Aslambek Aslakhanov told the Interfax news agency.
The hostage-taking was the fourth attack blamed on Chechen rebels to rock Russia since last week.
Those have included a bomb at a bus station on August 24, bomb attacks that brought down two airliners the next day and killed 90 people and an attack by a female suicide bomber outside a Moscow subway on Tuesday that left nine dead and 51 people wounded.