After almost two months of heavy urban warfare, the besieged city of Sirte seemed Sunday to be on the verge of falling to Libya’s revolutionaries. But by nightfall, as with so many battles in this war, it was not clear this one was over.

Anti-Gaddafi forces said they had taken the university, the main hospital and a convention center whose hilltop position gives a strategic advantage to whoever controls it. Forces pushing in from the south, east and west were going street by street to eliminate pockets of snipers, government officials said, and Libya’s temporary leader said he expected the battle to be over in a week.

But counterattacks later in the day pushed some of the forces back and fighting continued, according to media reports.

Sirte, 278 miles east of Tripoli, carries strategic and symbolic importance in the battle for Libya. It is ousted leader Moammar Gaddafi’s home town, a place where he spent lavishly to build glitzy hotels and villas and to buy loyalty. And it lies at a central point on the main coastal road that connects Libya’s east and west.

The prolonged fighting there has stymied the formation of a permanent government. Libya’s temporary leaders have said they will consider the country liberated only when Sirte is under their control. At that point, they say, they will declare an interim government that can start moving the country toward a new constitution and elections.

But Sirte, a city of about 100,000 people, one-fifth of whom are from Gaddafi’s tribe, has been harder to subdue than many had hoped.

“We thought that we wouldn’t need any fight in the city after the fall of Tripoli,” said Hassan al-Droe, the Transitional National Council’s Sirte representative, who is working from Benghazi, a city in the east. “I thought that Gaddafi and his family would leave the whole country after the fall of Bab al-Aziziya,” the former leader’s Tripoli compound.

Instead, when Tripoli fell, many of Gaddafi’s forces fled and regrouped in Sirte and Bani Walid. TNC officials said they did not know how many loyalists were holding out or the amount of arms and ammunition they possess.

“They are military soldiers, very well trained, very well armed,” said Atia Mansouri, a former Libyan air force officer who is a military consultant helping coordinate NATO forces and TNC fighters. By contrast, the revolutionary forces have suffered from a lack of organization and training, which has delayed their advance and cost lives, he said.

Three groups have been pushing into Sirte, with some under traditional-style military command and some acting as “a guerilla operation,” Mansouri said, adding that the groups have had trouble communicating with one another.

TNC officials say they have advanced slowly into Sirte to avoid the kinds of heavy civilian casualties Gaddafi forces inflicted on the city of Misurata by shelling indiscriminately. Residents fleeing Sirte have described abysmal conditions, with heavy destruction and a lack of food and fuel.

The International Committee of the Red Cross estimates that about 20,000 people have been displaced on the eastern and western sides of the city. It says it does not know how many civilians remain inside.

Revolutionary commanders have coordinated their attacks with NATO, which has a mandate to protect civilians. Last week, they declared a cease-fire to let civilians escape before a final push by revolutionary forces that started Friday and included NATO airstrikes.

Television footage Sunday showed revolutionary fighters shooting into the convention center and shredding green loyalist flags there. But in many cases, anti-Gaddafi forces have advanced only to retreat in the face of heavy counterattacks.

“Some are saying 24 hours; this is not right,” Mansouri said. “It is very difficult to name a time. They have to get it street by street.”

TNC officials have speculated that Sirte and Bani Walid are sheltering one or more of Gaddafi’s sons, which may be one reason fighters there continue to battle so fiercely for what appears to be a losing cause. TNC officials say they believe Gaddafi may be somewhere in the south.

Another reason for the fierce defense may be that loyalists don’t know what they might face if they surrender. About 80 percent of people in Sirte are not partisans of either side, but they have been misled by Gaddafi’s propaganda, said Droe, the TNC’s representative from the city.

“They are afraid of the revolutionaries,” he said. “He has put in their minds that they are coming to kill you, to rape your women.”

After the fall of Tripoli, Droe said, Gaddafi forces cut power to towns, blocked access to satellite television and erected a screen in Sirte’s main square that showed videos of previous pro­Gaddafi rallies in Tripoli to make people believe the capital was still under his control.

Refugees fleeing Sirte in recent days have said that people caught with generators have been publicly executed, and some refugees have expressed surprise when they hear of the fall of Tripoli.

Faris Alam, 19, a student from Benghazi who returned Saturday after taking supplies to revolutionary fighters in Sirte, described the city as largely abandoned, adding, “They still have the green flag in a lot of places.”

Revolutionary forces have used loudspeakers to urge Gaddafi forces inside Sirte to lay down their arms, promising they will be treated well, Mansouri said, adding that several hundred have surrendered but that many remain mistrustful. “They fear they will be killed, but they are wrong,” he said. “If they surrender, they will be in the best position.”

Sirte refugees in outlying villages, including onetime Gaddafi supporters, are forming committees to plan temporary housing and schools, Droe said.

He told of a former loyalist who came to Benghazi to apply to form a local council. The man appeared to have accepted the new system, Droe said. “He said, ‘Okay, it’s done. We are Libyans. We have to live as everybody else is living.’ ”