ZAWIYA, Libya – Rebels closed in on Moammar Gadhafi on Friday, pushing back his fighters in a fierce battle in one key coastal city and seizing another town as they advanced toward the capital of Tripoli.

The territory still under Gadhafi’s control has been shrinking dramatically in the past three weeks, with opposition fighters moving closer to Tripoli, a metropolis of 2 million people, from the west, south and east.

At the nearest point, rebel fighters are just 30 miles west of Tripoli, in the coastal city of Zawiya, where battles raged Friday over control of the city center. Gadhafi’s forces pounded rebel-held areas of the city with rockets, mortars and anti-aircraft fire, but by nightfall were pushed out of a multistory hotel on the square.

NATO’s bombing campaign has made it difficult for the regime to send massive reinforcements to Zawiya, enabling the rebels to maintain a hold over much of the city, their biggest prize in months.

But Friday’s onslaught by regime forces also signaled that an opposition push toward Tripoli could be arduous and bloody. The massive fire at one point pinned down some two dozen rebel fighters behind a building about 200 yards from Zawiya’s central square, a symbolic prize in the battle for control of the city of some 200,000 people.

The group was commanded by Rida Shaeb, 47, an electrician who wore his workman’s blue coveralls to the front line. “We are here to fight,” he said. “We are not going back, even if we die.”

East of the capital, rebels seized the city of Zlitan after clashes with regime forces that left 31 rebels dead, a spokesman said. Zlitan had been a major obstacle in the rebels’ push toward Tripoli from the east.

“The fighters have liberated Zlitan and they are fighting west of the city,” said Munir Ramzi of the opposition Misrata Military Council. He said Gadhafi’s forces were fleeing after Friday’s victory and the rebels are in control of the city.

With the recent advances, the rebels cut off the coastal road to Tripoli from the east and the west, and also control a city along a major supply road to the capital from the south.

Libyan rebels said Friday that Abdel-Salam Jalloud, a close Gadhafi associate who was once the No. 2 top regime official, has defected.

Jalloud helped Gadhafi stage the 1969 coup that propelled him to power and transformed Libya from a monarchy to a republic. He was Gadhafi’s most trusted deputy for two decades but began to clash with the leader starting in the 1990s.

Rebel spokesman Mahmoud Shammam said that Jalloud had fled to a rebel-held area in the western mountains and was on his way to Europe. Jalloud issued no statements, but Shammam said he had confirmed the defection on the telephone.

Jalloud’s defection, if confirmed, would be the latest crack in what remains of Gadhafi’s regime, although the two men had fallen out. Rebels also said Jalloud could provide valuable information about Gadhafi’s inner circle.

Rebel official Abdel-Hafiz Ghoga said the defection “gives us assurance that Gadhafi is weakening” while stressing that Jalloud would face justice for any crimes committed when he was part of the regime.

As fighting intensified, the International Organization for Migration announced plans to start evacuating “large numbers” of Egyptians and other foreigners, including some journalists, from Tripoli in coming days.

In recent weeks, the rebels gained momentum, following long stretches of deadlock in the 6-month-old civil war. Fighting had erupted after anti-regime protests swept the country in February.