CAIRO — Rebels pouring in from the countryside strengthened their grip on much of the Libyan capital, setting up checkpoints and securing buildings even as longtime leader Moammar Gadhafi evaded their grasp and pockets of his loyalists continued to put up fierce resistance.

Heavy fighting rumbled around Gadhafi’s Bab Azizia compound in southern Tripoli, and throughout the capital rebels said they had sustained heavy losses. The opposition forces claimed control of about 80 percent of the city, which was at once jubilant with waving flags and precarious with the rattle of gunfire.

Attention quickly focused on how the Transitional National Council, the rebels’ governing body, would impose order on a fractious tribal nation battered by six months of revolt. The rebels are prone to divisions, and Western officials worry that power struggles and the desire for revenge may threaten stability much as they did after the fall of Saddam Hussein in Iraq.

But the rebels’ sense of momentum suffered a blow early today when Gadhafi’s son and onetime heir apparent, Seif Islam, appeared at a Tripoli hotel that remained in the hands of Gadhafi’s forces. The rebels had claimed Sunday that they had captured him. Another son, Mohammed, was reported to have escaped rebel custody.

Gadhafi’s tanks and snipers took strategic positions in several Tripoli neighborhoods. Still, it was uncertain if the mercurial man who referred to himself as Brother Leader and ruled the nation for nearly 42 years could muster a potent counterattack.

NATO indicated that it would continue its airstrikes against the Libyan leader’s army. That poses a high risk of civilian casualties in Tripoli, a dense urban landscape with more than 1.6 million people.

But the pressing question for rebel leaders and NATO commanders was Gadhafi’s whereabouts. Unlike on previous days, the Libyan leader released no new audio broadcasts.

In comments to reporters, Seif Islam said his father remained in Tripoli.

“We do not know if he is inside or outside Libya,” Mustafa Abdul Jalil, the head of the rebel government, said during a news conference in the eastern city of Benghazi, the insurgents’ de facto capital.

East of Tripoli, rebels said Gadhafi’s forces were retreating from Port Brega on the coastal highway toward Surt, Gadhafi’s birthplace and tribal stronghold.

The rebels received support from governments around the world, including Egypt, which is struggling to build a democracy after its revolution overthrew President Hosni Mubarak in February.

The United Nations said it was organizing a meeting with the Arab League and African Union to help Libya emerge from Gadhafi’s legacy.

“Now is the time for all Libyans to focus on national unity and reconciliation,” Ban Ki-Moon, secretary-general of the U.N., told journalists. “This is a hopeful moment, but also there are risks ahead.”

Prime Minister David Cameron of Britain, one of the main participants in the NATO campaign against Gadhafi, told reporters in London that “his regime is falling apart and is in full retreat.”

The latest information is “that the vast majority of Tripoli is now being controlled by free Libyan forces, although fighting continues and some of it is extremely fierce,” he said.

Rebels in pickup trucks laden with high-caliber guns roared into Tripoli throughout Monday. Insurgent leaders set up checkpoints and secured buildings. Representatives of the Transitional National Council met with Gadhafi loyalists to prevent chaos from sweeping the capital.

The effort was part of a larger aim to create unity among disparate tribes and ethnicities whose differences Gadhafi had manipulated for decades.

It remains to be seen, though, whether Berbers in the west, whose rebel forces reached the capital first, will cooperate with tribes from the east. Both sides were united in defeating a dictator, but those bonds will be tested in debates over the distribution of Libya’s oil wealth and a new national government.

“The challenge for Libyans will be to agree on transitional leaders, but this won’t be easy given all the sects and tribes,” said Ammar Ali Hassan, an analyst in Cairo. “The problem will be reaching a consensus.”

Internal divisions widened among insurgents in recent months.

They led to the assassination in July of Gen. Abdul Fatah Younis, the rebels’ military commander and former head of security for Gadhafi. U.S. and European officials have been meeting with rebel leaders in Benghazi in an attempt to instill democratic principles and avoid recrimination in the country.

“The question is: Who is getting all those weapons the rebels are seizing in the many stockpiles in Tripoli?” said Michael Corgan, a professor of international relations at Boston University. “How are those weapons going to be used? Who will keep order once the forces loyal to Gadhafi and his mercenaries are neutralized? If all the Gadhafi apparatus of state power is dismantled, who rules?”