TRIPOLI, Feb 20 (Reuters) - A convoy carrying the prime minister of Libya's U.N.-backed government and the heads of an allied parliament and presidential guard came under fire in Tripoli on Monday, but none of the three were harmed, officials said.

A spokesman for the U.N.-backed government, Ashraf Tulty, said the motorcade had been hit by shooting as it passed through Tripoli's Abu Salim district. It was unclear who was behind the shooting or whether it was a targeted attack, he said.

Security in Tripoli is highly volatile. The city is controlled by multiple armed groups, some of which support the U.N.-backed Government of National Accord (GNA) and some of which oppose it. There are frequent clashes and gunfire.

The convoy that came under fire on Monday was carrying GNA Prime Minister Fayez Seraj, State Council head Abdurrahman Swehli, and the commander of a fledgling Presidential Guard, Najmi Nakua, Tulty and a spokesman for Swehli said.

Tulty said reports from Swehli's office that two guards had been injured were inaccurate, though he said some bullets had struck the convoy's armoured vehicles.

"There is an ongoing investigation into the source of the shooting. They want to figure out if there was any party behind the shooting or if it was random," Tulty said.

A GNA statement said Seraj, Swehli and Nakua had opened a new criminal investigations unit in Tripoli on Monday morning, and published pictures of the three at the event. It did not mention the shooting.

Seraj and the GNA's other leaders arrived in Tripoli last March in an effort to unite Libya's factions and end the turmoil that has roiled the country since its 2011 uprising.

But his government has remained half-formed, unable to win backing from power-brokers in eastern Libya or effectively impose its authority in Tripoli and the west.

(Reporting by Aidan Lewis; Editing by Ralph Boulton) ((Aidan.Lewis@thomsonreuters.com ; +216-29850352;))