BEIRUT — For more than a month, insurgents fighting President Bashar Assad’s forces had been on the march in central Syria, getting within a few miles of the fourth-largest city of Hama. Many in the opposition hoped they would cut a main government supply line to Aleppo and ease the pressure on the rebels there.

But the ambitious campaign has been severely hampered by the rebels themselves, mostly due to infighting that broke out last week.

It’s a recurring theme of opposition discord and rivalry that Assad has exploited throughout Syria’s 5-year-old civil war.

The five-week offensive, which saw insurgents break government defenses and capture more than two dozen villages and towns, was spearheaded by the Salafi-jihadi extremist Jund al-Aqsa group.

The advance so alarmed Syria’s army command that it eventually rushed one of Assad’s most trusted and prominent officers, Col. Suheil al-Hassan, and his elite unit to defend the strategic region.

The Hama region, which has a religiously mixed population, is an intersection between central and northern Syria and the Mediterranean coast. The rebels hoped their blitz would reduce pressure on the northern city of Aleppo, which has been under blistering Syrian and Russian air attack.

The key for the opposition was to cut government supply lines between Aleppo and Assad’s strongholds in Damascus and the coastal region.

That did not happen.

On Oct. 7, heavy fighting broke out in the nearby Idlib province between Jund al-Aqsa and the powerful, ultraconservative group Ahrar al-Sham. That group blamed the other for assassinating several of its local commanders.

Both groups then withdrew from battling government troops, allowing the army to launch a counteroffensive and regain control of 14 villages and towns since the weekend.

The infighting “turned the situation upside down,” said Turkey-based opposition activist Ahmad al-Ahmad, adding that government forces within three days regained 30 percent of the ground they lost in a month.

The fighting eased after the al-Qaida-linked Fateh al-Sham Front said Jund al-Aqsa will be folded under its command — a move that will make the front much more powerful. Sporadic skirmishes continue, but the fighting has effectively wrecked both the rebel offensive and any possible rescue of Aleppo.

Such disunity and rivalry has plagued opposition and armed rebel groups in Syria from the beginning. Turf wars and internal power struggles have often impeded rebel advances, allowing government forces to take advantage and gain territory.

Since late August, rebels have captured areas in Hama province close to Idlib province, which is near the border with Turkey and is the biggest insurgent stronghold in Syria.

“We have many goals, and one of them is to cut the regime’s road leading to Aleppo,” a commander with Jund al-Aqsa in Hama said last week. The commander, who goes by the name of Lt. Col. Karmo, did not elaborate.

On Tuesday, the same commander said that while his men had not withdrawn, Ahrar al-Sham had pulled its fighters from front-line villages in Hama province, helping Assad’s troops regain control of much of what they lost in the past five weeks.

But al-Ahmad, the opposition activist, said both groups had abandoned their positions on the front lines in Hama.

Two Ahrar al-Sham officials did not respond to questions about the events.

A Syrian cabinet minister, Ali Haidar, told The Associated Press in Damascus on Wednesday that Hama was the “safety valve which the gunmen tried to open to alleviate pressure on Aleppo.” He said the rebels also aimed to open parallel fronts to divert government resources.

An opposition activist from Hama province who closely monitors the situation and has contacts with various factions said there were disagreements even before the fighting broke out between Jund al-Aqsa and Ahrar al-Sham.

One of the main disagreements that slowed the Hama offensive was how to run the city once it fell to the insurgents. Many in Hama feared that Jund al-Aqsa’s extremist ideology would be implemented, and they wanted only gunmen from the city to be in charge of security, the activist said.

The activist, who spoke on condition of anonymity for fear of reprisals by the insurgents, also said Hama’s merchants and elders opposed any situation that might put the city at risk of government airstrikes, similar to what Aleppo has endured.

Hama has been relatively calm since Syria’s crisis began, apart from anti-government protests at the start of the 2011 uprising that turned into civil war.

The elders fear a repetition of what happened in 1982 when President Hafez Assad, the father of the current leader, cracked down on a Muslim Brotherhood-led rebellion in Hama. Government troops razed much of the city in a three-week air and ground attack, killing between 10,000 and 20,000 people.

The insurgents named their current operation in Hama after Marwan Hadid, a Muslim militant and native of the city who was killed under torture in government jails in 1976.

In addition to capturing towns and villages, the insurgents also have advanced close to Hama’s air base, one of the country’s largest and the launching point for government warplanes attacking rebel positions in central Syria.

The government and its Russian allies have responded to the offensive with intense airstrikes, and Assad’s forces have regained the upper hand for now.

Rami Abdurrahman, head of the Britain-based Syrian Observatory for Human Rights, said only two small rebel groups were still trying to repel the government counteroffensive.

“The situation is very bad, and if it continues that way, the regime will retake ground it lost two years ago,” he said.