KABUL, Afghanistan — On a recent afternoon, I found myself squeezed into the back seat of a car, one of about 50 vehicles in a procession recklessly speeding through the Afghan capital. The passengers — all men, all members of Afghanistan’s Shia Muslim minority — were headed toward the Kart-e-Sakhi shrine, where the previous night a suicide attacker loyal to the Islamic State, the radical Sunni group, had killed more than a dozen Shias.

In the front, three men occupied the passenger seat, limbs splaying out of the open door. The cars raced through the streets, forcing traffic to halt and make way. The black-clad men thumped their chests in religious fervor, shouting “Ya Hossein” in allegiance to the Shias’ third imam and waving flags depicting children in green headbands that said the mourners belonged to the “House of Hussein.” The scene had the marks of a sectarian conflict in the making. In fact, that was just what they were determined to prevent.

It was Oct. 12, and Ashura, the holiday when Shias commemorate the martyrdom in 680 A.D. of Imam Hussein, a grandson of the Prophet Muhammad and, according to them, his rightful heir. (Shias believe the prophet chose Hussein’s father, Ali, as his successor; Sunnis believe he picked his own father-in-law, Abu Bakr.) The men I rode with were intent on mourning their fellow faithful the same way they emulate the suffering of their imam: by self-flagellating with fists, chains and knives.

Afghans have lived through decades of conflict but have largely been spared the kind of sectarian war that ravages other countries in the region, such as Iraq and Pakistan. The Islamic State, also known as ISIS or ISIL, has seemed intent on changing that since it surfaced in Afghanistan last year, when pockets of fighters in the eastern part of the country started pledging allegiance to the group.