An undertaker stands near the unmarked graves of Islamic State militants killed during an attack in March. (Lorenzo Tugnoli/For The Washington Post)

The families arrived at the cemetery in the night carrying the bullet-riddled corpses of their sons and brothers, residents recalled. One by one, the bodies were placed in unmarked graves, outcasts even in death.

The dead men had been fighters for the Islamic State. All Tunisians, they had crossed into Libya to join the terrorist group’s affiliate there. In March, they returned with other radicalized Tunisians in an attempt to seize Ben Guerdane, a smuggling hub 20 miles from the border. Dozens of the militants were killed in fierce clashes with security forces, including at least 10 who were raised here in the southeastern corner of the country.

Only eight were buried in the cemetery.

“Some families refused to take the bodies,” said Samir Naqi, a senior police official.

That Ben Guerdane, long known as an incubator for jihadists, was not captured was a victory for Tunisia. But the attack and its aftermath revealed the North African nation’s fragility as it struggles to contain the toxic fallout from the Arab Spring uprisings five years ago, and represented an escalation in the Islamic State’s ambitions.

Tunisians form the largest contingent of foreign fighters in Syria and Iraq. But with U.S. and Russian airstrikes hammering them there, and travel bans and stricter border controls in place, more Tunisians are joining the Islamic State in Libya. Increasingly, Libya’s conflict is spilling into Tunisia, the only country to emerge as a functioning democracy after the revolutions.

The Islamic State, also known as ISIS and ISIL, asserted responsibility for two attacks in Tunisia last year: in the resort town of Sousse and at the Bardo Museum in the capital, Tunis. Scores of people died, mostly foreign tourists, at the hands of Tunisian gunmen believed to have been trained in Libya.

The sophisticated raid on Ben Guerdane — a multi-pronged assault on Tunisian security forces — triggered fears that the militants are seeking a safe haven in Tunisia, whose secular history and Western leanings have made it a target of religious extremists.

“It’s now clear that Libya is a threat for us,” said Mohamed Maali, the head of Tunisia’s anti-terrorism department. “With ISIS fighters under pressure in Syria, the new destination is Libya, where, unfortunately, there’s no authority and no order. For them, it’s paradise.”

Ben Guerdane is the nearest city to the Libyan border along the Tunisian coast. (Lorenzo Tugnoli/For The Washington Post)
‘Come and join our fight’

The streets that run past the low-slung houses of Ben Guerdane are unpaved. Entire fields are repositories for trash. There are no factories, no universities, none of the economic development seen in the northern tourist regions of Tunisia. On any given day, scores of unemployed young people sit in cafes or laze on street corners. Countless livelihoods are linked to illicit trafficking of weapons, fuel and consumer goods to and from Libya.

Or to conflict.

“Because of the poverty and the marginalization, the youth of Ben Guerdane find themselves with no options to remain here,” said Salem Chouat, 80, a former mayor. “At the same time, they meet with ISIS recruiters who promise lots of money, cars and a great life. So what do you expect the youth to do? Their choice is either smuggling or ISIS.”

Hundreds of young men have left Ben Guerdane over the past three decades to wage jihad in Iraq, Afghanistan and Bosnia, radicalized in part by a repressive regime that persecuted Islamists.

Their fighting skills were so valued that Abu Musab ­al-Zarqawi, the slain leader of ­al-Qaeda in Iraq, the predecessor to the Islamic State, was known to have said, “If Ben Guerdane had been located next to Fallujah, we would have liberated Iraq.”

A man waits to cross the border with Libya. (Lorenzo Tugnoli/For The Washington Post)

After the 2011 revolution that ousted Tunisian dictator Zine ­el-Abidine Ben Ali, religious extremists took advantage of the new freedoms and a security vacuum to help radicalize another generation of youths. More than 4,000 Tunisians joined the Islamic State and other armed factions in Syria and Iraq, often traveling there after receiving training and indoctrination in Libya, U.N. investigators said. An additional 1,000 to 1,500 went to fight in Libya. Many of the militants were from Ben Guerdane.

Now, there are signs that the Islamic State is telling foreign fighters to go to Libya and stay there, underscoring the shifting geography of the terrorist network. The group established a stronghold in the city of Sirte after the death of Libyan dictator Moammar Gaddafi in 2011. According to U.S. intelligence officials, the militants view the coastal city as a possible fallback option if Raqqa, the Syrian seat of their self-declared caliphate, falls to the U.S.-led coalition.

In October, Tunisian Defense Minister Farhat Horchani announced that at least 250 Tunisian Islamic State fighters had left Syria, after the Russian airstrikes began, to fight in Libya.

In one recruiting video posted online last year, an Islamic State commander standing on the shores of the Mediterranean Sea, presumably in Libya, urges Muslims to join the fight against Gen. Khalifa Hifter, an anti-Islamist commander whose militias control parts of eastern Libya.

“To all the brothers in the Arab Gulf islands, Egypt, Tunisia and Sudan,” the Islamic State commander says, “to all those who are protective of God’s religion, come and join our fight.”

If proof was needed that the Tunisians listened, there was evidence in the aftermath of a U.S. airstrike on an Islamic State training camp in the Libyan city of Sabratha on Feb. 19.

Most of the 41 killed were Tunisians. They probably included Noureddine Chouchane, a top commander who was recruiting and training Tunisians to attack inside their homeland, according to Tunisian and Libyan officials.

Two weeks later, Tunisian militants stormed Ben Guerdane.

Hussein Abdul Kabir at the location in Ben Guerdane where his brother Abdul Athi was executed by Islamic State militants. (Lorenzo Tugnoli/For The Washington Post)
Highly coordinated attack

Hussein Abdul Kabir remembers the four masked gunmen who entered his family’s compound in a Toyota pickup truck. It was shortly after 6 a.m. His brother Abdul Athi, head of Ben Guerdane’s counterterrorism brigade, was walking out of his house.

As everyone scattered, the gunmen chased Abdul Athi. One speaking Arabic with a Tunisian accent yelled, “The non-believer, Abdul Athi,” Hussein recalled. Then two gunmen, unmasked, emerged from the house next door and ran in from the opposite direction. Abdul Athi was cornered.

“The assassins knew the neighborhood well,” said Hussein, a bull-necked man with sad, dark eyes. Dried blood still stains the ground where his brother died.

“I recognized one of them,” Hussein said. “He is from Ben Guerdane.”

In a different part of town, militants attacked the police station, triggering heavy clashes. Some opened fire at a military barracks from the minaret of a mosque, attracting return fire that left it pocked with large holes. Street battles unfolded against security forces in other enclaves.

During one battle, Salim Dhawi huddled in his cellphone shop as a fighter crouched in a firing ­position nearby. “He said: ‘Don’t worry. We are the Islamic State,’ ” Dhawi recalled. “ ‘We are here to protect you from this ­non-believer government.’ ”

Witnesses said five militants erected a checkpoint in front of the Midway Cafe, as if they were already the lords of the town. They clutched Kalashnikov rifles and rocket-propelled grenade launchers. Some wore military fatigues. They began stopping cars and checking IDs.

At one point, they dragged a customs official from his car and shot him dead, said Mohamed Ali, a co-owner of the cafe. After the killing, he said, one fighter with a Tunisian accent declared, “Tomorrow, we will be ruling you.”

A shop that was destroyed by fighting in March. (Lorenzo Tugnoli/For The Washington Post)

By the time the clashes ended, 52 militants, 12 security force members and eight civilians were dead, said Naqi, the senior police official. All of the militants killed, he added, have been identified as Tunisians, including three commanders who were from Ben Guerdane.

Was the assault designed to test the security forces’ capabilities? Was it revenge for the U.S. airstrike? Was it an attempt to create a foothold in Tunisia as the United States and its allies plan a possible military intervention in Libya?

It may have been all of the above, Tunisian security officials said.

Despite the repelling of the militants, a sense of collective unease lingers.

A security barrier made of sand berms and water trenches, covering nearly half of Tunisia’s ­285-mile border with Libya, was mostly complete in February. Yet many, if not all, of the militants crossed over from Libya. Five days before the attack, Tunisian security ­forces killed several militants in a house near Ben Guerdane. Yet the outfit managed to regroup and stage the bold, highly coordinated strike.

Tunisian security forces said they later found safe houses in Ben Guerdane where weapons from Libya were stored, evidence of the relationship between the Islamic State and smuggling cartels that help fund and drive the conflict.

Some of Abdul Athi’s own relatives are suspected of being Islamic State loyalists, recruited to get close to the man who knew the most about the militants’ network in the town. The house the two gunmen emerged from belonged to a cousin whose wife’s two brothers had fought in Syria, Tunisian security officials said.

“He was targeted because he knew all the people of Ben Guerdane who sympathized with ISIS,” said his father, Mohammad Abdul Kabir, as he clutched his fatherless grandson, Mahab. “He knew all the people who went to Libya for training.”

Mahab Abdul Kabir, 3 years old, sits with his grandfather Mohammad and his uncle Hussein. (Lorenzo Tugnoli/For The Washington Post)
‘Still learning democracy’

Since the attack, dozens of suspects have been arrested amid concerns about more cells in Ben Guerdane. Three mosques suspected of extremist teachings have been shut down. The border crossing into Libya is closed for Tunisians younger than 35 — unless they have a letter from their parents stating their purpose.

Security forces are closely monitoring the relatives of alleged fighters.

One of Hamza Jarie’s close relatives is among those being watched. Last year, Tunisian authorities branded Jarie, who is from Ben Guerdane, as one of the country’s most dangerous terrorists. He was captured in Sabratha by a Libyan militia after the U.S. airstrike in February. In a video posted online last month, Jarie confesses to working at an Islamic State propaganda radio station.

The relative in Ben Guerdane said he was held and interrogated in prison. Security forces routinely raid his home in the predawn hours. He is not allowed to travel overseas, and he is stopped at security checkpoints whenever he leaves town. The taint has prevented him from finding a job.

“I am paying for something I didn’t do,” said the relative, who spoke on the condition of anonymity because he fears retribution from security forces. “This aggression by the state is what makes people disappointed in the state,” he said. “This is what makes terrorists.”

Senior Tunisian security officials say such tactics are necessary. They also say concerns about human rights are hampering their ability to stop terrorists.

“We are still learning democracy. But, personally, I can’t understand human rights for terrorists. They want to kill us,” said Maali, the anti-terrorism chief.

Sipping coffee at a crowded sidewalk cafe, former mayor ­Chouat warned that the security measures are unlikely to stop Ben Guerdane’s youths from flowing next door or fighting from inside Tunisia — as long as the south remains without good schools, roads and jobs.

“If the situation continues like this, we may lose full control of our youth,” he said. “We fear it will make them angrier at the government. We fear it will push them to do all kinds of bad things.”

The war against the Islamic State hits hurdles just as the U.S. military gears up

Israel, Hamas and Egypt form unlikely alliance against Islamic State affiliate

How the Syrian revolt went so horribly, tragically wrong

A Syrian rebel’s slaying in Turkey points to the long, lethal reach of ISIS