A large contingent of al-Shabab militants stormed a Somali military encampment Thursday, killing dozens of government-aligned soldiers and civilian bystanders.

The incident was rare in its brutality — many of the dead were reportedly beheaded — as well as its location in the semiautonomous region of Puntland, hundreds of miles northwest of the capital, Mogadishu, where al-Shabab has focused its recent attacks.

Military officers gave conflicting reports of the number of soldiers killed when speaking to news agencies. Estimates ranged from 20 to 70, though all agreed it was the worst al-Shabab attack in Puntland in many years. Through its own Shahada News Agency, al-Shabab claimed that it killed 61 soldiers.

The attack came just days after Puntland sentenced five al-Shabab fighters to death after they were found driving a truck laden with explosives through the region’s biggest city, Bosaso, in late April. The events on Thursday unfolded in the village of Af Urur, about 60 miles southwest of Bosaso. Puntland is also home to a group of fighters that splintered off from al-Shabab last year to form an Islamic State affiliate.

Al-Shabab is an Islamist group whose leaders have pledged allegiance with al-Qaida. They are most active in southern Somalia, where they once exercised almost total control, but since 2011 have been pushed out of most major cities by African Union troops.

The troops attacked on Thursday belong to the Puntland Dervish Force, an official paramilitary that receives substantial funding from the United States.

The number of people killed by al-Shabab rose sharply last year, as compared to 2015. A study by the Africa Center for Strategic Studies found that the group was responsible for 4,281 deaths, a 30 percent rise. Those numbers make al-Shabab the deadliest militant group in Africa, as attacks by Boko Haram in Nigeria dropped precipitously in 2016 after years of accelerating violence.

Between 1991 and 2012, Somalia effectively had no internationally recognized federal government and was in a state of civil war. The northern regions of Puntland and Somaliland assumed differing degrees of autonomy during those years, and the country has yet to fully reintegrate. Elections earlier this year brought Mohamed Abdullahi Mohamed to power. Known as “Farmajo,” he is seen by many as a leader capable of working toward national unity.

A resurgent al-Shabab has compounded the misery that has beset Somalia stemming from more than two years of pervasive drought. Nearly 7 million Somalis are dependent on some form of humanitarian aid, accounting for more than half the country’s population. Thursday’s attack plays into fears that al-Shabab will expand its militancy during the holy month of Ramadan. Their attacks often prevent aid organizations from going about their work.