CAIRO — Libya edged closer to full-blown civil war on Friday as forces of an eastern commander clashed with pro-government ­militias near the capital, Tripoli, and an effort by the U.N. chief failed to stop the offensive.

A battle for control of Tripoli would mark the most significant escalation of violence in oil- and gas-rich Libya since the toppling of Libyan dictator Moammar Gaddafi in 2011 following a populist rebellion backed by NATO bombings.

After meeting Friday with the renegade warlord, Khalifa Hifter, in the eastern Libyan city of Benghazi, U.N. Secretary General António Guterres said in a tweet that he was leaving Libya “with a heavy heart and deeply concerned.”

Hifter reportedly told Guterres that his offensive on Tripoli will continue, according to the al-Arabiya television network.

“I still hope it is possible to avoid a bloody confrontation in and around Tripoli,” Guterres wrote in his tweet.

That hope has dimmed. Hifter’s force, which calls itself the Libyan National Army, pushed forward toward the capital and clashed with militias that support the U.N.-installed, Western-backed government.

By nightfall, Hifter’s troops claimed to have taken an area near Tripoli’s old international airport, but there was no independent confirmation.

With dozens of militias in the heavily populated capital, urban warfare could cause heavy civilian casualties.

It also would deepen the chaos and lawlessness that has turned Libya into a hub for smuggling migrants to Europe and at one time allowed the Islamic State to establish a foothold in the coastal city of Sirte. Increased insecurity could allow the militants to regroup and set off a new rush of people fleeing to neighboring countries or over dangerous sea routes in the Mediterranean.

Hifter’s army is aligned with a separate eastern government. The internationally recognized government is based in Tripoli and controls only parts of the west. But a constellation of well-armed militias in Tripoli, as well as in cities such as Misurata, view Hifter as another potential dictator in the mold of Gaddafi and have mobilized against him.

Hifter was a general in Gaddafi’s army who defected and then spent years living in Northern Virginia. He returned to Libya to take part in the revolution against Gaddafi.

The offensive took the country and the international community by surprise. Guterres had traveled to Libya this week in the hope of bringing the rival sides to a national reconciliation conference scheduled for later this month. Its main goal was to set up a road map for long-delayed elections.

On Thursday, though, Hifter’s force overran and swiftly captured the town of Gharyan, about 60 miles south of Tripoli. The commander then sent out a recorded message to his troops that was posted online, urging them to march toward the capital.

“We are coming, Tripoli, we are coming,” said Hifter, whose forces have pushed toward the city since Thursday.

It remained unclear whether Hifter’s advance was intended to gain a stronger negotiation position in any talks over the future of Libya. On Thursday, the United States and other countries called for an immediate de-escalation of tensions. France and the United Arab Emirates are widely said to be Hifter’s key backers.

Fearing a spillover of refugees, neighboring Tunisia has tightened control over its border, said its Defense Ministry. The U.N. Security Council has also taken up the issue.

“The U.N. is committed to facilitating a political solution and, whatever happens, the U.N. is committed to supporting the Libyan people,” Guterres said in his tweet.

Late Friday, the U.N. Security Council called on Hifter to pull back his forces, warning that further advances would jeopardize any hopes for stability in Libya. “There can be no military solution to the conflict,” said Germany’s U.N. Ambassador Christoph Heusgen, the president of the council, reading a statement from the body.

Foreign ministers of the Group of Seven nations — the United States, France, Britain, Germany, Italy, Japan and Canada — also called for a halt to the military actions.