Libyan rebel leaders said their forces hunted down and clashed with supporters of Muammar Gaddafi who had been posing as rebel fighters to infiltrate the opposition's eastern stronghold.
The overnight battle killed four from each side and added to a sense of crisis within the rebel movement.
Libya's shaken rebels are trying to rid their ranks of enemies after the assassination last week of their military chief, Abdel Fattah Younes.
The leadership insists the killing was the work of Gaddafi's regime, but several witnesses have said Younes was killed by fellow rebels.
As officials pieced together events leading up to Sunday's gun battle, they announced that a faction of fighters called al Nidaa was actually made up of Gaddafi loyalists posing as rebels.
The revelation could raise questions about the loyalty of rebel factions and sap the movement of much-needed unity in its push to topple Gaddafi nearly six months after the revolt began.
Suspicions about al Nidaa were confirmed, a rebel security leader said, when intelligence officials determined the group was behind two prison breaks on Friday in the rebels' de facto capital of Benghazi that freed 200 to 300 inmates, including pro-Gaddafi mercenaries, fighters and other regime loyalists.
"These people took advantage of the chaos that resulted from the killing of Younes and entered and attacked the military prison and the (civilian) Kuwaitiya prison," said the rebel's deputy interior ministry, Mustafa al-Sagezli.
On Sunday before dawn, rebel forces tracked al Nidaa members to a factory where they were hiding out and sent in negotiators to try to persuade them to surrender. When they refused, the rebel units besieged the factory, killing four of the Gaddafi fighters, said rebel Information Minister Mahmoud Shammam.
A battlefield commander who participated in the operation, Ismail Salabi, said four of those posing as rebels were also killed and 25 were captured. He described them as Libyans from the southern part of the country who belonged to the Gaddafi Brigades.