Some 30 children and their teachers have been freed unharmed after being held hostage for several hours at their kindergarten in Malaysia.

Police used tear gas before storming the compound in a suburb of Muar town in Johor state.

The hostage-taker, reportedly armed with a hammer and machete, was injured and is now in custody, police say.

A similar incident last year prompted the government to issue safety advice to schools.

"We have ended the hostage taking. The children and teachers are safe. The hostage-taker armed with a hammer and machete has been taken to a local hospital," one police officer told the AFP news agency on condition of anonymity.

Malaysia's Star newspaper reported that the hostage-taker had been shot and the children had been taken to hospital for a check-up.

According to the newspaper, before intervening, the police tried to lead negotiation with the hostage-taker for several hours, while at the same time, heavily-armed troops from the elite Special Actions Forces and ambulances stood nearby getting ready for a potential assault.

Early in the negotiations, the man - reported by local media to be mentally unstable - had threatened to kill the children if he was not given a gun, and had also asked for some food, the newspaper reported.

As the news spread, anxious parents gathered around the police cordon, hoping that the negotiation will be successful, however it seems that after trying to reason the man for more than seven hours, the Malaysian forces decided to launch the assault and neutralise the criminal.