A machete-wielding man who took 30 children and four teachers hostage for six hours in a Malaysian kindergarten has died after being shot by police, an official said Friday.

None of captives was harmed during the tense hostage drama Thursday in the southern city of Muar in Johor state.

The crisis ended when the 40-year-old man was shot in the head by a single bullet, said Jalaluddin Abdul Rahman, the state's deputy police chief.

The hostage taker was taken to hospital where he died late Thursday, another police official said on condition of anonymity because he was not authorized to speak to the media.

During negotiations with the man, he threatened to kill the children unless he was given a gun, he said.

The officer said the man was wielding a machete and a hammer when he barged into the kindergarten early in the morning, sparking a standoff with police.

The man, believed to have mental problems, forced the hostages to go upstairs in the two-story building. Police special forces later managed to enter the ground floor and were heading up the stairs when the man attacked them with his weapons and a fire extinguisher, the officer said.

Police had no choice but to shoot the man, he said.

The children had been heard singing in what was believed to be an attempt to calm the man, the Bernama news agency reported.