The abduction of the five on Saturday and of another member of the Egyptian embassy's staff a day earlier came after Shaaban Hadeia, a prominent commander in the rebellion that ousted Moamer Kadhafi in 2011, was arrested in Alexandria.
The Egyptians' release was confirmed after Hadeia, head of the Operations Centre of Libya's Thuwar (revolutionaries), announced his release himself on television.
"The five diplomats and a further member of staff of the Egyptian embassy are free," Libyan Deputy Foreign Minister Abderrazak al-Gridi told AFP.
"They are at home and they are safe. They were treated well and their health is good," Gridi said, without elaborating on the circumstances of their release.
A Libyan security official speaking to AFP on condition of anonymity said the kidnappers freed the six as part of a deal between Tripoli and Cairo.
The official said the kidnappers, who have not been identified, demanded the release of Hadeia, also known by his nom de guerre Abu Obeida.
The first batch of Egyptian hostages was freed on Sunday.
"The two other members of the embassy will be freed when Abu Obeida arrives in Libya," the security source had explained before the final releases.
The Operations Centre had posted on Facebook that there could be a "possible reaction from the thuwar."
But one of the group's leaders, Adel al-Ghariani, told AFP they were not involved in the kidnappings.
The presidency of the General National Congress, Libya's highest political authority, has ordered its mission in Cairo to demand an explanation for the ex-rebel leader's arrest.
Egypt's foreign ministry spokesman Badr Abdelatty had confirmed Hadeia was detained in Egypt but did not say why.
"If Hadeia's involvement is not established, naturally we will release him," Abdelatty told AFP, adding that investigations were ongoing.