— The black-and-white flags of al-

Qaeda’s wing in Syria still flutter over this impoverished city in northern Lebanon. And the anger that fueled a major clash last month involving Sunni extremists still simmers underneath a shaky calm.

The Lebanese military now controls Tripoli. But the militants who fought street-by-street battles with soldiers represent a growing challenge to the stability of this already deeply divided country.

The militants are Lebanese citizens who went to fight in Syria’s civil war, assisted by money and weapons from Sunni politicians here, according to religious leaders, politicians and military officials.

The Sunnis sympathize with the rebellion led by Syria’s majority Sunnis against a government dominated by Alawites, whose faith is an offshoot of Shiite Islam.

In Syria, the young militants became radicalized by such groups as the Islamic State and Jabhat al-Nusra, al-Qaeda’s Syrian affiliate, religious leaders and politicians say. Now, back in Lebanon, they are increasingly clashing with the military.

“Their goal is to turn the people against the army,” said Sheik Nabil Rahim, a religious leader in Tripoli who has contact with local militants.

Attacks against the military have risen sharply over the past year in predominantly Sunni areas of northern Lebanon. In Tripoli, the militants have used mosques in the Bab al-Tabbaneh neighborhood, a Sunni-dominated area, to recruit followers and store weapons. A series of attacks led to the confrontation with the army last month. About a dozen soldiers and nearly 30 militants were killed in the fighting, in which the military used helicopters and tanks.

Scores of fighters were arrested, while others fled after some of the worst violence in this city in years.

Spillover from next door

Lebanon is a religiously diverse country with a Shiite plurality. The Sunni militants have attracted followers because of long-standing issues of poverty and government neglect in Sunni areas, analysts say.

In addition, many Lebanese Sunnis fume over the fact that this country’s main Shiite militia, Hezbollah, is fighting in Syria to support its longtime ally, President Bashar al-Assad.

In response, local Lebanese Sunnis have offered financial assistance and arms to encourage young men here to fight in Syria against the Assad regime. Support from Persian Gulf states also has flowed through this city, with furtive arms shipments arriving by sea and then being taken overland to rebels in Syria, according to military officials, analysts and local religious leaders.

Politicians in Tripoli make little secret of the fact that Lebanese Sunnis are playing a role in the war next door.

“You can also make the same allegations against Hezbollah,” said Mustafa Allouch, a member of the Future Movement party.

Some Sunni politicians have provided cover for the militants. In 2012, authorities arrested a prominent militant, Shadi Mawlawi, on charges of links to al-Qaeda-inspired groups. When he was released, he was taken back to Tripoli in the personal car of a cabinet minister. Mawlawi emerged as a leading figure in the recent fighting.

Since the start of the Syrian uprising, militants in Bab al-Tabbaneh have regularly battled groups from an adjacent neighborhood that is inhabited by followers of the Alawite faith.

Increasingly, however, the Sunni militants have turned their weapons on Lebanon’s military, which they see as taking orders from Hezbollah.

“These militants have developed their own agenda. They no longer listen to the local politicians,” said Mohammad Obeid, an analyst who is close to Hezbollah, referring to Sunni militants in the Tripoli area.

Rahim, the Tripoli-based ­religious leader, said the militants support Jabhat al-Nusra and the Islamic State because they are seen as operating “above petty political squabbles and sticking to their principles.”

Local politicians have been forced to back away from the militants. They publicly threw their support behind the armed forces during the fighting in Tripoli last month.

“This was the first time the Sunni leaders issued such public support for the army,” said Elias Farhat, a retired Lebanese general. “These leaders are supposed to be moderates, but they gave weapons and political protection to these militants, and it’s coming back to haunt them.”

A security official in Tripoli expressed concern that local militants were increasingly coordinating with extremists in Syria who are tied to the Islamic State and Jabhat al-Nusra. Those Syrian-based fighters briefly seized the northern Lebanese city of Arsal in August. They captured more than 20 Lebanese soldiers before withdrawing, and they later beheaded at least two of them.

The official, who spoke on the condition of anonymity because he was not authorized to discuss the subject, said Mawlawi talked by cellphone to militants involved in the Arsal attack before the Tripoli fighting erupted.

Seen as protectors

Mawlawi and Osama Mansour, another militant leader who operated in Bab al-Tabbaneh, fled Tripoli during the clashes. The men, in their 20s, have spent time fighting with rebel groups in Syria.

After last month’s military operation, the security official said, the army discovered Kalashnikov rifles, rocket-propelled grenades and more than 600 pounds of explosives at two mosques in Bab al-Tabbaneh that were frequented by the two militants.

In September, Mawlawi and Mansour said during an interview with a local television station that they had great affinity for Jabhat al-Nusra, although they had not formally pledged allegiance to the group.

“We are close to Jabhat al-Nusra in terms of policy, ideology and practice,” Mansour said.

A friend of the two militants, Sheik Walid Tabboush, said residents of Bab al-Tabbaneh view the pair as defending them against the military, which has a heavy presence in the neighborhood. Earlier this year, Mansour issued a religious edict that urged followers to kill the head of Lebanon’s military, Gen. Jean Kahwaji.

“These men feel they have a duty to protect the area in the name of religion,” Tabboush said. “So people started supporting them.”

Suzan Haidamous contributed to this report.