BAGHDAD — Militants fired mortars on a Shiite shrine north of Baghdad late on Thursday, and in the confusion that followed, three suicide bombers in military uniforms infiltrated the compound and blew themselves up, the Iraqi authorities said.

At least 36 people were killed and more than 40 were wounded.

The attack occurred just days after a minivan packed with explosives detonated in central Baghdad, killing at least 250 people and wounding nearly 200.

Thursday’s attack occurred in Balad, about 55 miles from Baghdad, at the mausoleum of Sayyid Muhammad bin Ali al-Hadi, a son of the 10th imam, who is revered among Shiites. Crowds of pilgrims had gathered there to celebrate Eid al-Fitr, which ends the holy month of Ramadan.

Two of the bombers detonated their explosives near the gate of the mausoleum, and a third rushed deeper into the shrine and threw hand grenades at pilgrims, the authorities said.