ZAWIYAH, Libya – Rebel forces fighting government troops were held up in their advance to the Libyan capital, Tripoli, on Wednesday, facing fierce resistance in a key western city as thousands of refugees from cities still under leader Moammar Gadhafi’s control sought to escape anticipated violence.

Fighters carrying light weapons streamed into Zawiyah as families in packed sedans headed in the opposite direction, toward the Nafusa mountain range, which has been under rebel control since March.

Zawiyah is seen as critical to the rebel advance to the capital, 27 miles to the east. It is home to one of two oil refineries still under Gadhafi’s control, and the coastal highway connecting Tripoli with the Tunisian border passes through it.

“We will oust this dictator and turn Libya into a perfect nation,” said Abdel Bassed Ammar, a rebel from Zawiyah.

The rebels have made significant advances in the past two weeks, causing the United States and other members of an international coalition supporting them to voice hope that Tripoli would soon fall into their hands.

Their gains appeared to have stalled Wednesday in Zawiyah, which after four days of clashes was still the scene of chaotic back-and-forth fighting between the rebels and Gadhafi supporters. Rebels managed to halt the output of oil from the city’s refinery, but without apparent immediate effect in the capital, which has become dependent on gasoline smuggled from neighboring Tunisia.

Families fleeing Tripoli in new Korean-made sedans drove through the violence in Zawiyah in order to get to rebel-controlled areas. Rebel forces counting the refugees heading to the mountains said that more than 2,000 families had passed their checkpoint in the village of Bir Aiab.

Farook Sherwan, a father of three from the capital, stepped out of his car to register with the rebel administration, saying that he expected “a big battle” in Tripoli soon.

“In the last days, we saw fewer and fewer government checkpoints and increasingly heard the sounds of gunfire,” he said.