The Kenyan miners were marched off in the predawn dark on Tuesday, some barefoot, others shirtless.
The Somali militants methodically separated the Christian workers from the Muslims and took the Christians to the side of a hill, near a gravel pit. Then they ordered the disbelievers to lie face down.
According to the Kenyan authorities, the militants killed 36 people, most of them young men. Many were shot in the back of the head, at close range, and some were decapitated. It appeared all the Muslims had been spared.
The killings, which followed a similar sequence on a passenger bus less than two weeks earlier, unnerved the Kenyan public and led to the ouster of Kenya’s top security chiefs.
“Innocent Kenyan lives have been lost, in a most harrowing manner, to these animals,” said Kenya’s president, Uhuru Kenyatta.
But, he said, “We will not flinch.”
Kenya has been severely hampered by Somali militants next door, a problem that never seems to go away. It started in the 1960s and became acute in the early 1990s, when Somalia’s government collapsed and hundreds of thousands of refugees, and waves of gunmen called shiftas, fled into Kenya.
In the past few years, the Shabab militant group, an affiliate of Al Qaeda operating from southern Somalia, has been terrorizing Kenya with dozens of attacks, from rolling grenades into bus stops to slaughtering shoppers, as happened last year in an upscale mall in Nairobi.
On Tuesday, the Shabab asserted responsibility for the gravel pit killings, saying, as they have before, that they had executed disbelievers and crusaders in response to Kenya’s deployment of peacekeeping troops into southern Somalia.
Analysts say that the Shabab, who have recently been hit by scores of defections, are now trying to foment a religious war and that the Kenyan security forces must not rise to the bait.
In past crackdowns, Kenyan police officers have rounded up thousands of Somalis, brutalizing civilians and locking innocent men, women and children in a stadium. At the same time, several Muslim preachers have been assassinated, setting off antigovernment riots along Kenya’s coast. A secret counterterrorist unit of the Kenyan police is widely suspected of killing the preachers, which seems only to have increased tensions.
“From a propaganda standpoint, I suspect that Shabab is trying to play the role of a Robin Hood, swooping in at random to avenge the wrongs done to the Muslim communities,” said Bronwyn Bruton, deputy director of the Africa Center of the Atlantic Council in Washington.
The goal of the Shabab, she said, is “to draw down indiscriminate fire on the Muslim population” and to goad the Kenyan security forces into counterproductive dragnets and purges.
In Kenya, the Shabab have now become the enemy everyone fears. They have been cast out of nearly all of their former strongholds in Somalia by a coalition of East African forces, including the Kenyans, and in September, American commandos killed the longtime Shabab leader.
The group has lost all the major income-producing ports it once controlled. With the Islamic State gaining strength in Iraq and Syria, the Shabab are no longer a magnet for foreign fighters.
But clearly, the Shabab are not finished. The group still fields hundreds of gunmen, many young and enthusiastic, and its sympathizers across East Africa have carried out their own deadly attacks. Kenya has become the prime target, especially the loosely governed north, where the quarry and bus attacks took place: a vast, arid, sparsely populated area where public services, especially security patrols, are few.
According to Kenyan police reports, around 20 gunmen crept into the quarry area Tuesday at 1 a.m. Most of the miners were asleep. Two were beheaded in their tents.
Even before this attack, Kenyans were infuriated with the breakdowns in public safety, recently holding a protest in Nairobi, the capital, accusing Mr. Kenyatta of weakness.
On Tuesday, hours after the quarry attack, he responded by accepting the resignation of the national police chief and dismissing the internal security minister, a former hotel manager described by many Kenyans as alarmingly unqualified.
Mr. Kenyatta did not immediately name a new police chief, but he announced that Joseph Ole Nkaissery, a retired general, would be the next internal security minister. Mr. Ole Nkaissery is from the same ethnic group, the Masai, as his predecessor. Commentators instantly accused Mr. Kenyatta of playing ethnic politics at the expense of security reform.
Afyare A. Elmi, a political science professor and Somalia specialist at Qatar University, said Kenya’s next move was crucial.
“Anything that has the appearance of collective punishment will only help the Shabab,” he said. “Kenya’s response should be measured.”