(Adds minister's quotes, bomb planted, details)
By Hani Amera and Ulf Laessing
TRIPOLI, March 21 (Reuters) - A bomb exploded on the runway of Libya's main airport on Friday, the transport minister said, highlighting the deteriorating security situation in the north African country almost three years after Muammar Gaddafi was ousted.
Supposedly one of the best guarded places in Libya, unknown people managed to get onto the runway at Tripoli International Airport, plant an explosive device at dawn and detonate it using a timer, Transport Minister Abdelqader Mohammed Ahmed said.
Authorities closed the airport, the gateway into Libya, for several hours. There is little traffic after midnight as foreign airlines avoid late flights due to the poor security at night in the capital, where the government is unable to control militias which helped oust long-time leader Gaddafi in 2011 but have kept their guns.
"There was a small explosion," Ahmed said. "When security and the airport protection force arrived they found a timer."
Officials had first suspected rockets fired by militias had landed on the runway as gunfire could be heard during the night in the capital. Rival militias often fight over territory or influence in Tripoli or the rest of the country.
Authorities reopened the airport by using first an alternative runway. Mainly Libyan airlines restarted operations in the afternoon.
"We cancelled all flights," said the country head of a foreign airline with several daily flights to Tripoli.
European carriers such as Lufthansa and British Airways fly to Tripoli apart from Arab carriers.
Ahmed said authorities would improve airport security but analysts say the nascent police and army, still in training, are no match for battle-hardened militias seizing at will oil fields or ministries to grab power and oil revenues.
(Reporting by Reuters Television; Writing by Ulf Laessing; Editing by Janet Lawrence)