Two gunmen who massacred tourists at a Tunisian museum received their weapons training in Libya, a top security official said Friday, underscoring the growing threat posed by militant camps in disintegrating regions of the Middle East.

The Tunisian gunmen traveled illegally in December to Libya, which shares a porous border with its North African neighbor, Rafik Chelli, the country’s security chief, told a local television station.

He said authorities did not know details about the type of training the men received. Interior Ministry officials had previously told relatives of one of the militants that the young man had journeyed to the eastern Libyan city of Derna, according to an interview with a friend of the family’s. That city is controlled by Islamist militants, including a group that has proclaimed loyalty to the Islamic State.

The two Tunisian jihadists, identified as Yassine Laabidi and Saber — also known as Hatem — Khachnaoui apparently returned to Tunisia to carry out the worst attack here in more than a decade. Armed with assault rifles, they gunned down 21 foreign tourists and a security officer on Wednesday at the Bardo National Museum, a showcase of ancient Roman mosaics.

The revelation of a Libyan link was a wake-up call for Tunisia. Officials here have long feared that the violence in Libya, where numerous armed groups have battled for power since the overthrow of Moammar Gaddafi, would spill into this fledgling democracy.

Hundreds march through the Tunisian capital to mark not only their Independence Day, but also in protest of attack on their national museum. (Reuters)

But lawmakers here said security forces either lacked the proper tools and training to track the jihadists, or had been too relaxed in their surveillance of would-be militants.

Signs also emerged Friday of security lapses at the Bardo museum, which is next to the country’s legislature. Police officers assigned to guard the museum were not at the gate when the gunmen arrived, the deputy speaker of parliament said Friday. He said the officers were at a cafe across the street drinking coffee.

For years, Tunisia’s authoritarian leaders imposed secular practices in this largely Muslim country. But Tunisia has emerged as one of the biggest sources of foreign fighters for the Islamic State, which holds large tracts of territory across Syria and Iraq where it has trained and deployed thousands of militants.

The Islamic State claimed responsibility for Wednesday’s attack in Tunis, which killed tourists from Europe, Japan and Colombia. A French citizen died Friday of wounds sustained in the attack, French authorities said.

A group loyal to the Islamic State recently seized the Libyan city of Sirte and has carried out attacks in the Libyan capital, Tripoli. But other extremist groups also operate in Libya, including al-Qaeda-inspired Ansar al-Sharia. This was the first time the Islamic State has claimed responsibility for an attack in Tunisia.

“It is imperative we fight terrorism with all of our efforts,” Tunisian President Beji Caid Essebsi said in an address Friday. The fight “requires national unity and vigilance” by all institutions, he said.

On Friday, hundreds of Tunisians flocked to Avenue Habib Bourguiba in central Tunis for a rally marking Independence Day that turned into an anti-terrorism demonstration. French colonial rule ended in Tunisia in 1956.

Demonstrators waved Tunisian flags, and a local band played nationalist songs. Some people held aloft signs reading “Je Suis Bardo,” French for “I am Bardo,” echoing the defiant phrase “Je Suis Charlie” that circulated after the Paris attacks in January that began at the satirical newspaper Charlie Hebdo.

The avenue also was the center of protests that ousted Tunisian President Zine al-Abidine Ben Ali in 2011. Tunisia was the birthplace of the Arab Spring, a series of revolts that toppled several authoritarian leaders, but devolved into bloody conflicts in Libya, Syria and Yemen.

Authorities on Friday said they had bolstered security across the Tunisian capital. Officials said law enforcement officers were patrolling the main Mediterranean port in Tunis as part of a new security plan to protect vital installations. Police also were deployed Friday to guard the headquarters of Tunisia’s state-run radio. A spokesman for the Interior Ministry said there was a threat against Radio Tunisia, but he did not give further details.

To tackle the rise of homegrown militance, activists and analysts said, Tunisia needs a program to rehabilitate militants returning from places such as Syria and Libya. Political leaders blamed poverty and inadequate religious education for the increase in the number of Tunisian-based jihadists.

“We don’t have any other choice but to beat it. But it has to be a comprehensive approach,” commented Said Ferjani, a high-ranking official in Ennahda, a large moderate Islamist party.

Tunisia’s security forces needed improvement, he said, and “our economy is in very bad shape.”

It was important, he said, that “there is no collective punishment and that we do not infringe on people’s rights.”

He also said the country needed a new breed of Islamic scholars, “who not only have an in-depth knowledge of theology but also sociology, and Western philosophy.”

“Tunisia’s role is as a bridge between the East and the West,” he said. “We should play that role.”

Hend Hassassi in Tunis and Brian Murphy in Washington contributed to this report.

Watch: Islamic State claims responsibility for museum rampage

Attack stokes fears across North Africa

Bardo museum is home to amazing treasures