BIR SHAEB, Libya - Libyan rebels fought their way into the strategic city of Zawiya west of Tripoli on Saturday in their most significant advance in months, battling snipers on rooftops and heavy shelling from Moammar Gadhafi's forces holding the city.

Zawiya is a key target for rebels waging a new offensive launched from the mountains in the far west of Libya, an attempt to break the deadlock in combat between the two sides that has held for months in the centre and east of the country.

A rebel force of about 200 fighters advancing from the south reached a bridge on Zawiya's southwestern outskirts, and some rebels pushed farther into the city's central main square. They tore down the green flag of Gadhafi's regime from a mosque minaret and put up two rebel flags. An Associated Press reporter travelling with the rebels saw hundreds of residents rush into the streets, greeting the fighters with chants of "God is great."

Gadhafi's forces then counterattacked, unleashing rounds of heavy shelling and gunfire could be heard as rebels and government troops battled.

Regime snipers were firing down from rooftops on the rebels, said one resident, Abdel-Basset Abu Riyak, who joined to fight alongside the rebels when they entered the city. He said Gadhafi's forces were holed up in several pockets in the city and that there were reports of reinforcements coming from Tripoli, though there was no sign of them yet. He said NATO airstrikes had hit Libyan military positions near the city the night before.

Zawiya's residents rose up and threw off regime control when Libya's anti-Gadhafi revolt first began in February. But Gadhafi's forces retaliated and crushed opposition in the city in a long and bloody siege in March.

Speaking to the AP by telephone, Abu Riyak said residents were now joining up with the rebels' assault, saying, "95 per cent of Zawiya's people are with the revolution."

"There is shooting from all sides," said another rebel, 23-year-old Ibrahim Akram. "The people joined us. Fierce clashes are still ongoing, but thank God our numbers are great."

But Gadhafi is likely to fight hard to keep control of Zawiya. The city of about 200,000 people, about 30 miles (50 kilometres) west of Tripoli on the Mediterranean coast is key because it controls the main supply road to the capital from the Tunisian border and is the site of the sole remaining oil refineries in the west still under the regime's control.

The state of government forces after months of punishing NATO airstrikes is not known. The best armed and equipped units, led by Gadhafi's sons, have been involved in fighting at the main fronts -- around the city of Misrata, east of Tripoli, and at the oil port of Brega in the centre of the country. Libyan state TV said Zawiya was "under control" and that "armed gangs have been defeated," citing a military official.

The rebel force has been advancing into the coastal plain for the past week from the Nafusa Mountains, an opposition stronghold about 60 miles (100 kilometres) to the south. Commanders have said the plan is to seize Zawiya and other nearby towns and then move on Tripoli itself, Gadhafi's stronghold.

At the same time, rebels were attempting to seize control of another strategic town, Gharyan, south of Tripoli.

In the morning Saturday, rebels claimed control of Gharyan, saying they had moved into the centre of the town and that Gadhafi's troops had withdrawn. But several hours later, regime forces returned with reinforcements and the two sides clashed, said rebel spokesman Gomma Ibrahim.

Gharyan lies at the northern end of the Nafusa Mountains, and Gadhafi's hold on the town had been a sticking point for rebels who have taken control of most of the range. The town lies on the main road leading directly from Nafusa to Tripoli, 50 miles (80 kilometres) to the north on the coast.

Libya's revolt began in February, with the rebels quickly wresting control of much of the eastern half of the country, as well as pockets in the west.

But since April, the conflict has been locked in a stalemate. Despite months of NATO airstrikes hitting regime forces, rebels have failed to budge the main front lines, particularly at the oil port of Brega.

Rebels were claiming some progress at Brega, saying they seized part of the residential zones around its oil terminal. The Benghazi-based rebels' military spokesman, Col. Ahmed Bani, said that rebel fighters are clashing with Gadhafi forces to take control over the rest of the town. "Very soon all Brega will be liberated," he said.