Mustafa Nuh had reportedly been held by gunmen from the western town of Zintan.
Meanwhile, Tripoli is observing a three-day strike after militias from Misrata city opened fire on demonstrators, killing more than 40 people on Friday and Saturday.
The Misrata militia have been ordered to leave Tripoli within three days.
Two years after its revolution, Libya still lacks a stable government.
The rival militias from across the country which united to topple Col Muammar Gaddafi in 2011 have so far refused to disarm.
Several different groups entered the capital to force Col Gaddafi from power and some have remained there ever since.
The BBC’s Rana Jawad in Tripoli says that in the absence of a central government to exercise power over the whole country, each city – and militia – is looking out for its own political and financial interests.
Some are believed to have links to al-Qaeda, others want to gain more power for their region, or town, while some realise they would lose their influence if they gave up their weapons.
Mr Nuh was bundled into a car after arriving at Tripoli international airport on Sunday, but military sources told the BBC he was released on Monday morning.
He was kidnapped with former rebel commander Alaa al-Hafs, who managed to escape.
Mr Hafs told the BBC Mr Nuh had been taken captive by men from Zintan.
“I know that he was beaten but also that he’s OK,” Mr Hafs added.
Mr Nuh was freed following the intervention of the Shura Council of Zintan, made up of local elders, he said.
Zintan has the most powerful brigades in Tripoli and some of them are loosely attached to the defence ministry, our correspondent says.
Militias from Zintan are still holding Col Gaddafi’s son, Saif al-Islam, are and refusing to hand him over to the authorities in Tripoli.
At least 43 people were killed on Friday and Saturday when Misrata gunmen opened fire on protesters who were demanding they leave Tripoli.
In a joint statement on Sunday, Misrata’s local council and the council of elders said all militia groups from the city – without exception – must pull out of Tripoli within 72 hours.
Shortly afterwards, Khalil al-Ruwaiti, who heads a unit under the Misrata Shield brigade, confirmed to the BBC that his fighters would leave the capital.
The brigade is not part of the militias which clashed with the protesters on Friday.
Emotions have been running high in Tripoli since the clashes, and Misrata’s statement will be seen as a positive development, our correspondent says.
Some of the heaviest fighting of the 2011 conflict took place in Misrata and some residents and militiamen want this to be recognised.