* Tunisia cracking down on Ansar al-Sharia militants
* Disorder in Libya allows militants to train, gain arms
* Ennahda-led government ready to step down in three weeks
By Patrick Markey and Tarek Amara
TUNIS, Oct 20 (Reuters) - Tunisia's Prime Minister Ali Larayedh said Islamist militants are exploiting anarchy in neighbouring Libya to get training and smuggle weapons across North Africa's porous borders.
His coalition government is grappling with an Islamist militant group known as Ansar al-Sharia, which is one of the most radical to emerge since Tunisia's 2011 uprising against autocratic President Zine al-Abidine Ben Ali Ben Ali.
Security is a sensitive matter for Larayedh's ruling moderate Islamist party, Ennahda, which has agreed to step down in three weeks to end months of unrest set off by the assassination of two secular leaders by Islamist militants.
As well as Ansar al-Sharia, North Africa is home to al Qaeda in the Islamic Maghreb and other Islamist militants such as those led by veteran commander Mokhtar Belmokhtar, who claimed responsibility for the attack on Algeria's Amenas gas plant in January, in which nearly 40 foreign workers were killed.
France's military campaign to oust al Qaeda-linked Islamist fighters from Mali this year prompted some to enter southern Libya, where the government in Tripoli exerts scant control.
"There is a relation between leaders of Ansar al-Sharia, al Qaeda in the Islamic Maghreb and Ansar al-Sharia in Libya. We are coordinating with our neighbours over that," Larayedh, who was interior minister before becoming premier, told Reuters.
"Extremists in Tunisia have profited from the situation in Libya and they get their weapons from Libya. They have benefited and they have gotten training in Libya."
Larayedh, who spent more than a decade in prison for being a member of a banned Islamist party before the uprising, was speaking shortly after Tunisian forces killed 10 members of Ansar al-Sharia near Goubellat close to the Algerian border.
Tunisian authorities said gunmen had attacked two police patrols in the north of the country and had been planning assaults on security force buildings and the military.
It was the worst violence in Tunisia since Larayedh's government declared Ansar al-Sharia a terrorist organisation two months ago, accusing it of assassinating Chokri Belaid and Mohamed Brahmi, two secular opposition leaders.
Ansar al-Sharia's leader in Tunisia is a former al Qaeda fighter in Afghanistan, who is accused of inciting his followers to attack the U.S. embassy compound in Tunis a year ago.
"We are chasing down the last members of this group Ansar al-Sharia. We are advancing in this war," Larayedh said in an interview at his presidential office in Tunis.
He said more than 300 members of the organisation had been arrested since the crackdown began.
Tunisian forces have been bombarding Islamist militants in the Chaambi mountains near Algeria. The militants, who holed up there after the French offensive in Mali, killed eight soldiers in Chaambi in July, some of whom had their throats slashed.
STICKY POLITICAL TRANSITION
Tunisia, where a series of Arab uprisings began in 2011, had been seen as a regional model, and its transition to democracy remains less violent than those in Egypt and Libya.
But Islamists, who were long oppressed under Ben Ali, have gained influence, fuelling debate about the role of political Islam in one of the Muslim world's most secular countries and one with the strongest ties to Europe.
Salafi Islamists have prevented concerts and plays being staged in some cities, and attacked alcohol vendors, saying they violated Islamic principles. For secular Tunisians, Islamists want to impose strict Sharia or Islamic law, which they feel threatens liberal education and women's rights.
Ennahda itself is split between conservatives and moderates.
Critics of Larayedh, a quietly-spoken man with glasses and a small moustache, say he is an uncompromising hardliner. But the former maritime engineer has taken some conciliatory steps, appointing political independents to major cabinet posts when he took office in February.
Ennahda's chairman, Rached Ghannouchi, who spent many years in exile in Britain, has long promoted a moderate form of political Islam which he says can work with modern democracy.
Ennahda won 40 percent in Tunisia's first post-revolt election for an assembly to draft a new constitution. It formed an interim coalition government with two secular parties.
But the political transition was knocked off track by the assassination of the two opposition leaders, which enraged those who believed Ennahda was too lenient on Salafi Islamists blamed for those killings and other attacks on secular Tunisians.
Now Ennahda has agreed that the government it leads will step down after three weeks of talks that start on Wednesday to form a caretaker government, set up an electoral commission and decide on a date for elections to put the country back on track.
"The government is ready to give up power in three weeks from the start of the talks. I am ready to give up my post even before the three weeks," said Larayedh.
Ennahda was one of the first Islamist parties to rise to power in the region after 2011, when many of its leaders gained government posts after years in jail or overseas exile.
Although its popularity has eroded during its period in power, Ennahda remains the best organised political movement in Tunisia. It faces several leftist and secular groups, as well as Nida Tounes, a party that includes figures from the Ben Ali era.
"This is a not a loss, more a part of the transition," Larayedh said of the government's resignation. "What our country needs is stability." (Writing by Patrick Markey; Editing by Alistair Lyon)