War came late to this little farming town set amid rolling hills in the Syrian countryside east of Aleppo, where the absence of upheaval was long construed as an implicit signal of support for the government led by President Bashar al-Assad.

But once the battle started in May, it unfolded at lightning speed, at least by the standards of a revolt that is dragging into its 17th month. Residents are celebrating their near-complete victory over regime loyalists after the town’s last army garrison fled Sunday, its food supplies gone and its morale shredded.

With that, al-Bab became the farthest point in a swath of rural territory stretching south from the Turkish border toward the city of Aleppo that has slipped beyond government control in recent weeks.

The unraveling of the regime’s authority here in this northern province has been overshadowed by the battles for control of the cities of Homs, Damascus and, most recently, the provincial capital Aleppo, where government forces are waging a full-scale offensive to recapture neighborhoods seized by rebels in recent days.

But even as Assad’s forces have poured resources into sustaining their hold on major population centers, they have steadily been losing control of the countryside, in a series of seesawing battles that have not yet proved decisive but that appear to be giving the momentum to the rebels. The story of the battle of al-Bab, an overlooked front in a war of many fronts, suggests that the government’s hold here was always more fragile than had been thought and that it has become significantly more so in the past few weeks.

This was a corner of the country that was assumed to be neutral in the conflict, a mostly Sunni enclave whose aloofness from the mayhem elsewhere helped sustain the government’s claim that it still commanded the loyalties of significant sectors of the population beyond its Alawite support base.

That the province of Aleppo was slow to join the uprising was due more to the government’s determination to prevent it from doing so than to a lack of resolve by its people, according to Ammar Osman, 29, an activist with the Coordination Union for al-­Baba City and Its Suburbs. With more than 4 million inhabitants, Aleppo is the most populous and prosperous of Syria’s 14 provinces, and its location on the border with Turkey endows it with strategic significance beyond its role as the country’s commercial and agricultural center.

“The regime was very tough here. They put in a lot of security forces. They know they can’t afford to lose Aleppo,” said Osman, who spent 45 days in jail last year for his efforts to organize protests.

A race to arms

On April 20, as bloodshed was accelerating elsewhere and the province of Aleppo was beginning to stir, everything changed in al-Bab. On that day, troops opened fire on a protest for the first time, killing seven people. Among them was Ammar Najjar, 20, an engineering student who had led calls for peaceful protests in the town.

His father, Kamal, wept last week as he recalled his son’s death. “He only asked for freedom from tyranny. This was his weapon,” he said, pulling his son’s camera phone from his pocket.

The killings triggered a race to arms in the town. On May 20, a group calling itself the Abu Bakr Battalion became the first to declare its formation. Within weeks, 14 more groups followed. With names such as the Martyrs of al-Bab, the Ansar Battalion and the Salman Farsi Battalion, they collectively describe themselves as part of the Free Syrian Army. But they have no formal contact with the army’s leadership, based in southern Turkey, according to Yasser Abu Ali, a rebel spokesman in the town.

“We rely only on ourselves,” he said. “Everything we have, we bought it with our own money or we took it from the regime.”

By July, the rebels had mustered enough weaponry and ammunition to launch an offensive to drive government forces from the town. The effort culminated July 18 in the much-trumpeted liberation of the post office, the last of a string of government institutions to fall to the rebels. For 24 hours, a regime sniper had held out on the roof until a Free Syrian Army fighter hit him with a rocket-propelled grenade, a moment described by many in the town and immortalized in a video posted on YouTube.

The town of 175,000 erupted in celebration. Rebel groups swarmed into the government buildings, schools and security institutions that had been seized in the previous days, hoisting the Syrian revolutionary flag and establishing new headquarters.

But it was an incomplete victory. On the southern edge of town, the army camp remained, too well fortified for the lightly armed rebels to capture. A little over 100 soldiers were there, outnumbered by the town’s 1,000 or so rebels but equipped with tanks, artillery and mortars. They also had the support of helicopter gunships, which have been employed more frequently as the regime’s hold on far-flung areas slips.

Army soldiers out of food

Over the next two weeks, as gunners repeatedly shelled al-Bab with tanks and mortars, 75 people died — a heavy loss in such a small community in such a brief period.

More than 50,000 people fled to outlying villages or to Turkey, 50 miles away. Those who remained stayed close to home, not knowing where or when the next shell might fall.

“Oh, God,” wailed Najjar’s mother, Amira Rajab, as a mortar shell landed nearby last week, signaling the start of another day of bombardment. Then she burst into tears.

As the town cowered, an even more desperate scenario was unfolding at the army camp from which the ordnance was being launched. On Friday, commanders at the camp sought to negotiate safe passage for their men and equipment. The rebels agreed — and then staged an ambush, destroying a tank and forcing the rest of the departing convoy back to the base.

“They’ve committed so many atrocities, and they’ve killed so many people here, we can’t let them escape,” said Abu Bakr, the rebel commander who heads the Abu Bakr Battalion. “We are at war. Plus, we don’t trust them. They might have shot at us.”

Two conscripts who defected that day later suggested that the plea was genuine. Surrounded by rebels and cut off from the outside world, the soldiers had run out of food. Those injured in clashes could not be evacuated for treatment. “The people there are very scared,” said Khalil al-Yusuf, who climbed over two fences and was picked up by rebels after negotiating his exit with a cousin in the Free Syrian Army in Damascus.

Early Sunday, as the rebels slept after a failed overnight attempt to fire a homemade rocket into the camp, the last members of the garrison made their getaway, covered by an onslaught of rockets fired from helicopters and a jet.

The town erupted once again. Rebels paraded through the streets with a tank, an artillery piece and a truckload of ammunition that had been left behind, firing into the air in jubilation — but only sparingly, because they said that they, too, were worried about running out of ammunition.

Within hours, a helicopter reappeared and began firing rockets. The celebrations subsided, and residents rushed indoors again.