As other students rushed to safety, their parents beat three of the four gunmen unconscious.
Four attackers stormed Siem Reap International School at around 9 a.m., grabbing children from at least 15 countries and demanding money, weapons and a vehicle.
Gunfire broke out inside the school, and hostage takers later told police they killed the 3-year-old Canadian boy because he was crying too much. Police moved in after they "threatened to kill the other children one by one," Information Minister Khieu Kanharith said.
Authorities said they managed to talk the attackers out of the building after giving them a minivan and $30,000 in cash. When the men got into the vehicle with four children, security forces closed the gate to the school compound and launched an assault, yanking the men from the van.
"They tried to shoot at the police with their AK-47. Apparently, the gun jammed, and at this point, the police came, smashed the windows, and arrested the four hostage takers," Liam Cochrane, managing editor of the Phnom Penh Post, told CBS Radio News.
They later described themselves to police as penniless, saying they had decided to prey on the children of rich foreigners after they failed to find work.
Nearly 40 children, some as young as 2, rushed past the school gate and into the arms of their panic-stricken parents — some of whom charged the hostage takers, beating three unconscious. Police shielded the fourth. All were taken into custody.
The crisis unfolded at Cambodia's tourism hub of Siem Reap, home to the famed 9th-14th century ancient temple complex, and quickly drew concern from governments around the region. The town in the country's northwest brings in millions of dollars annually for the cash-strapped government and is home to hundreds of foreigners.
Hundreds of people gathered outside the yellow school house during the tense situation, and three armored personnel carriers were parked on the road.
The identity of the attackers was unclear, even after the standoff ended. Prime Minister Hun Sen said they appeared to be security guards at the school, but teachers later said they did not recognize them.
Deputy Military Police Commander Prak Chanthoeum said they were villagers from the southwestern province of Kandal, who had hoped to find jobs in Siem Reap.
He said the hostage takers told police they decided to kidnap the children "because they believed their families are rich."
The men originally took about 70 people but later released 30 of them, Khieu Kanharith said.
They "were armed with shotguns" and had demanded money, six AK-47 assault rifles, six shotguns, grenade launchers, hand grenades and a car, said Prak Chanthoeum, who said three teachers were among those seized.
He later said $30,000 and a van were given to the gunmen, but they still refused to free the hostages and continued to demand weapons.
Then gunshots rang out from inside the building.
Prak Chanthoeum said some of the parents grabbed three of the hostage takers from police and began beating and kicking them. "We could barely control the angry crowd," he said.
"It's a bad ending for sure," said Denis Richer of France, after trying to comfort the father of the young boy who died. "He was completely lost, he asked me to look for his wife which I did. I found an ambulance to bring the couple to the clinic."
He and other residents were shocked at the violence, noting that Cambodia is finally on the road to recovery after decades of war.
"Cambodia is a quiet country now," said Richer, who teaches at another school in Siem Reap. "We feel safe here. I still feel safe here."
"I hope this is a one off occurrence," said David Reader, the British ambassador, who was visiting the town.
A Western resident in Siem Reap, who demanded anonymity, said she was told by a teacher at the school that the children, most of them aged 2 to 6, came from Cambodia, Italy, Indonesia, South Korea, United States, Japan, Ireland, Singapore, Great Britain, Australia, Canada, Philippines, Taiwan, Thailand and Switzerland.