(Adds quotes from French formin, Libyan officials)
By Marie-Louise Gumuchian and Ghaith Shennib
TRIPOLI, April 23 (Reuters) - France's embassy in Libya was hit by an apparent car bomb on Tuesday, injuring two French guards and bringing violence to the capital after attacks on foreign missions in the east.
It was the first assault on a diplomatic mission in Tripoli, considered safer than the rest of the North African country, since the end of the 2011 war that ousted Muammar Gaddafi, leaving Libya awash with weapons and roaming armed groups.
There have been several similar attacks, notably in the eastern city of Benghazi, where the U.S. ambassador and three other Americans were killed last September.
U.S. officials say militants with ties to al Qaeda were mostly likely involved in that attack but no-one has claimed it.
Al Qaeda's north African arm AQIM has warned of retaliation for France's intervention in Mali but there was no indication as to who was behind Tuesday's explosion at the embassy in Libya.
Residents living near the embassy compound, in the capital's Hay Andalus area, said they heard two blasts early in the morning around 0700 a.m. (0500 GMT).
"We think it was a booby trapped car," a French embassy official told Reuters. "There was a lot of damage and there are two guards wounded."
Mohammed Sharif, chief of Tripoli Police said "an explosive device was planted in a car parked outside the embassy".
A large chunk of the wall around the compound collapsed and one corner of the embassy building had caved in. Office cabinets lay scattered on the ground outside and water from a burst pipe ran down the street. Residents pointed to shrapnel belonging to the car they said had exploded.
French President Francois Hollande condemned the attack.
"France expects the Libyan authorities to shed light on this unacceptable act so that the authors are identified and brought to justice," he said in a statement.
Foreign Minister Laurent Fabius, due in Tripoli on Tuesday, said carnage was avoided only because the attack happened shortly before embassy staff would have been arriving for work.
"This is an attack that targets not only France but all countries that fight against terrorist groups," he said on BFM TV, adding that security would be stepped up across the region. Fabius said one of the two guards had been injured seriously and would be operated on in Tripoli.
The Libyan army cordoned off the compound as dozens gathered outside. An embassy employee arrived at the scene and burst into tears when she saw the destruction. She was let inside to join colleagues and French security staff.
One resident living less than 100 metres from the embassy said his windows shook when the first blast occurred.
"I was in my house sleeping, when I was woken up by a long explosion. I went to my front door and found that it had blasted out," Osama al-Alam, lives next door to the embassy, said.
"I went into the street and saw smoke everywhere. We heard shooting and went inside the house."
His own house was badly damaged. Two cars outside the embassy were burnt out, others damaged. A palm tree in one front garden had fallen onto a roof.
"I think there were two blasts, the first was very loud and then there was a smaller one," another witness said. "There was some black smoke at first, and then it turned white."
Libyan Deputy Prime Minister Awad al-Barasi, Interior Minister Ashour Shuail and Justice Minister Salah al-Marghani visited the embassy compound and neighbouring houses that were charred and damaged.
"We are in a critical stage and there are some who want to destabilise Libya," Barasi said. "This will not stop us from moving forward even though it is painful to see the damage."
Security remains precarious in post-war Libya, where militias often do as they please.
The bombing of the U.S. mission in Benghazi followed attacks on British, Red Cross and United Nations interests in the city.
Most foreign embassy staff and international aid workers have strict security in Tripoli and Benghazi remains off-limits to many foreigners. Libya has promised a special force to protect diplomats but so far only a few additional police cars can be seen outside embassies in the capital.
"This is a very worrying sign for the government," a Western diplomatic source said. "It will be a further deterrent for companies who have so far been reluctant to come to Libya."
Western countries have warned of growing militancy in North Africa following the deaths of at least 38 hostages in an attack on Algeria's In Amenas gas complex near the Libyan border in January, and the start of French military operations in Mali.
Al Qaeda's north African arm AQIM said on Friday it would retaliate after France sent troops to help Malian forces drive back an offensive by Islamist militants who had seized two-thirds of the country in the desert north.
"God willing, you shall see what will happen," AQIM's spokesman said in a twitter response to reporters on whether it planned future attacks on France.
"Repelling France's aggressive assault is an obligation of every Muslim not just al Qaeda."
(Additional reporting by John Irish and Leigh Thomas in Paris; Writing by Marie-Louise Gumuchian; editing by Anna Willard)