BAMAKO, Mali — This onetime model of African stability remained in a precarious state on Tuesday as the new military junta fought back an attempted countercoup by loyalist troops and asserted victory by day’s end.

Hours before the revolt broke out Monday, the junta’s leader, a youthful American-trained captain named Amadou Haya Sanogo confidently declared a leading role in Mali’s future in an interview at his barracks outside Bamako, the capital. There was no hint that his authority would be challenged later in the day, but soldiers were busy building a substantial protective wall in front of the dilapidated two-story military building that is his headquarters.

There were sporadic bursts of gunfire on a rainy May Day holiday, but soldiers on the street, diplomats and a high-ranking member of the junta said control had been re-established in Bamako, at least temporarily, after a night of shelling and tracer fire. Key positions — the state television station, the airport and the loyalist Djicoroni barracks — were under their command, said the soldiers, who appeared calm for the most part. Still, gunfire crackled over the Djicoroni barracks late into the afternoon.

The apparent triumph of Mali’s military bosses, less than six weeks after they chased the elected president from his palace overlooking the capital, seemed a further step in the consolidation of their control, despite pledges to restore civilian rule and democracy. It was a show of firepower, capped by the overrunning of the short-lived uprising’s center in the Djicoroni barracks. The high-ranking member of the junta, who asked not to be quoted by name, said there had been deaths on both sides, but could not say how many.