The soldiers drove an armoured vehicle through the gates of the palace usually used for ceremonial occasions then set off two explosions and fired scattered shots.
They claimed they were part of Madagascar's "new" army, an apparent reference to a faction that has rejected president Marc Ravalomanana.
The president is accused of misspending public funds and undermining democracy.
Opposition leader Andry Rajoelina has declared himself president and promised new elections within two years.
Anzeige