Forces loyal to Libyan strongman Khalifa Haftar were pushed back Friday from a key checkpoint less than 30 kilometres (18 miles) from Tripoli, checking their lightning advance on the capital, a security source said.
Pro-governmental militiamen from the coastal town of Zawiya, west of Tripoli, retook the base after a "short exchange of fire", the source said on condition of anonymity.
The advance by Haftar's forces on Thursday, which came as the United Nations prepares to convene a conference later this month on organising delayed elections, prompted UN chief Antonio Guterres to voice his "deep concern".
Guterres was in Tripoli for talks with the head of the UN-backed unity government, Fayez al-Sarraj, when the offensive was announced. He was due to meet Haftar in eastern Libya later on Friday.
The UN Security Council was also to hold an urgent meeting on the crisis as Western governments appealed for restraint.
Traffic was flowing normally past the checkpoint on Friday morning, an AFP correspondent reported.
Just a single armoured vehicle was seen. The allegiance of its occupants was not immediately clear.
The Zawiya militia is one of dozens that have proliferated since the overthrow of veteran dictator Moamer Kadhafi in a NATO-backed uprising in 2011 and are variously aligned with the UN-backed unity government in the capital and a rival administration in the east backed by Haftar's forces.
Most of the pro-Haftar fighters who briefly captured the checkpoint late on Thursday were rival militiamen from the town of Sabratha further west along the Mediterranean coast.
Dozens of them were captured and their vehicles seized, the security source said.
Pictures posted on social media of men in military uniform sitting on the ground purported to show some of those taken prisoner, but their authenticity could not immediately be verified.
The Tripoli Protection Force, an alliance of pro-government militias in the capital, said its fighters had taken part in the recapture of the checkpoint 27 kilometres (17 miles) to its south.
'Time has come'
A convoy of vehicles from Haftar's forces on Thursday pushed towards the city of Gharyan, some 100 kilometres (60 miles) south of Tripoli on Thursday, witnesses and military sources said.
Haftar said "the time has come" to take Tripoli in an audio message released on Thursday, pledging to spare civilians and "state institutions".
His forces' spokesman Ahmed Mesmari said they were "at the gates of the capital" on Thursday evening.
Unity government chief Fayez al-Sarraj on Thursday condemned Haftar's "escalation" and said he had ordered loyalist forces to prepare to "face all threats".
The UN Security Council was due to meet behind closed doors to discuss the crisis.
The United States and its allies issued a joint statement urging "all parties to immediately de-escalate tensions".
"At this sensitive moment in Libya's transition, military posturing and threats of unilateral action only risk propelling Libya back toward chaos," they said.
Russia called for "all possible efforts to fully resolve the situation with peaceful political means."
"We believe that the main thing is for any actions not to lead to renewed bloodshed," Kremlin spokesman Dmitry Peskov told reporters.
Analysts say the advance by Haftar's forces comes at a key moment as the UN bids to get elections back on track after an abortive effort last year.
"The risk of a flare-up has increased," said Jalel Harchaoui, a researcher at Clingendael Institute in The Hague.
"Capturing Tripoli... remains a possibility" for Haftar, with the support he receives from Saudi Arabia and its allies Egypt and the United Arab Emirates, he said.
Haftar held talks in Riyadh late last month and his forces have reportedly received major arms deliveries from the UAE, including aircraft, despite a UN embargo.
They already overran most of the remote oil fields and oasis cities of the desert south during an offensive earlier this year.
The government's writ is now largely confined to the narrow coastal strip around Tripoli and third city Misrata to its east.