* Flights to eastern towns of Labraq, Tobruk still operating
* Stoppage comes after mystery air raid on armed group in Tripoli
* Rival factions have turned Tripoli into battlefield (Power outage in western Libya, background, PVS CAIRO/TUNIS)
By Heba al-Shibani and Ahmed Elumami
TRIPOLI/BENGHAZI, Aug 21 Tunisia and Egypt's Cairo airport halted most flights to and from Libya on Thursday for security reasons, officials said, days after the Libyan government said unidentified war planes had attacked positions of armed groups in Tripoli.
Flights from Tunisia and Egypt to Libya had been operating on an almost daily basis until now, a vital link to the outside for Libyans and foreigners alike as fighting between rival factions in the capital escalated.
Libya has used the small Matiga airport in Tripoli for civilian traffic since the main airport was turned into a battlefield last month. The tower, runway and at least 20 aircraft have been damaged, officials have said.
When flying into Matiga, passengers can sometimes see smoke rising from battles in and around the main airport. Rebel groups who united to topple Muammar Gaddafi in 2011 have since turned on each other, spreading anarchy in oil-producing Libya and raising fears it may become a failed state.
In Tripoli two factions, one from the city of Zintan and the other from Misrata, have been fighting each other for control of the city for over a month.
The violence, the worst Libya has seen since the uprising against Gaddafi, prompted the United Nations and foreign embassies in Libya to evacuate their staff and citizens, and foreign airlines largely stopped flying to Libya.
However, flights from Tunis to the eastern Libyan town of Labraq, as well as from the Egyptian Mediterranean port city of Alexandria to Libya were still operating, a Libyan aviation official said on Thursday. A Tunisian transport official said flights to the eastern town of Tobruk were also still running.
Renegade General Khalifa Haftar claimed Monday's air attack on Islamist-leaning armed factions, which have been trying to expel their rivals from the capital.
But some analysts have questioned how outdated jets from the Libyan airforce - which were severely damaged during the 2011 uprising against Gaddafi - managed to stage a night attack flying 1,000 km from the east.
Haftar has used aircraft in Benghazi to attack Islamist brigades but with mixed success. Once a plane hit a university site instead of a militia camp, residents said.
Libyan television news channels have speculated that neighbouring countries or other parties may be behind the overnight air strikes. The United States, NATO and Egyptian officials have denied any involvement.
EXPLOSIONS, POWER OUTAGE
Tripoli residents reported loud explosions during the night but the city was quieter on Thursday than on previous days when street battles between armed groups had moved closer to the city centre.
In yet another setback for Libyans, power outages affected much of Tripoli and western Libya due to damage to a transmission station in Zawiya, the state electricity company GECOL told LANA, without providing details.
Monday's air attack have escalated a struggle between Islamist and more moderate militias as well as all the other forces vying for power and spoils in the OPEC-member nation.
Tripoli has largely slipped out of control of the government, with senior officials working from Tobruk in the far east, where the new parliament has based itself to escape the violence in Tripoli and Benghazi.
Libya's central government lacks a functioning national army and relies on militias for public security. But while these get state salaries and wear uniforms, they report in practice to their own commanders and towns. (Reporting by Tarek Amara, Ulf Laessing, Feras Bosalum, Ahmed Elumami and Ayman al-Warfalli; Writing by Ulf Laessing; Editing by Raissa Kasolowsky)