At least 47 people were killed on Thursday when Libya's worst bomb attack since the fall of Muammar Gaddafi hit a police training center as hundreds of recruits gathered for a morning meeting.

No group immediately claimed the attack in the western town of Zliten, but suicide blasts and car bombings have increased in Libya as Islamist militants have taken advantage of the North African country's chaos to expand their presence.

Late on Thursday the Islamic State militant group claimed another car bombing that killed at least seven in the oil port of Ras Lanuf. The port and a nearby terminal at Es Sider came under attack from militants earlier this week, in their most concerted effort to date against Libya's oil infrastructure.

In Zliten, Mayor Miftah Hamadi said the truck bomb detonated as around 400 recruits were gathering in the early morning at the police center. Zliten lies between the capital Tripoli and the port of Misrata.

"It was horrific, the explosion was so loud it was heard from miles away," Hamadi told Reuters by telephone, his voice choked with emotion. "All the victims were young, and all about to start their lives."

The charred remains of a vehicle lay strewn across the ground near the police academy building. Parked cars were mangled by the force of the blast.

Witnesses said residents ferried victims to Misrata hospitals in ambulances and cars, many with shrapnel wounds and some bodies too damaged to be identified.

Medical sources had initially said 65 people had been killed, including some civilians. But Fozi Awnais, head of the crisis committee for the health ministry in Tripoli, said later that 47 people had died and 118 more were wounded.

Since a NATO-backed revolt ousted Gaddafi, Libya has slipped deeper into turmoil with two rival governments and a range of armed factions locked in a struggle for control of the OPEC state and its oil wealth.

In the chaos, Islamic State militants have grown in strength, taking over the city of Sirte and launching attacks on oilfields.

On Monday, Islamic State fighters launched an attack on Ras Lanuf and Es Sider, Libya's biggest oil export terminals, which are situated between Sirte and the eastern city of Benghazi.

Clashes over three days had already had already left 11 guards dead and set seven oil storage tanks on fire before Thursday evening's car bombing.

The ports have been closed since December 2014, and Libya's oil output has plunged to less than one quarter of a 2011 high of 1.6 million barrels per day.

The Zliten blast was the worst since an attack in February last year when three car bombs hit the eastern city of Qubbah, killing 40 people in what officials described as a revenge attack for Egyptian air strikes on Islamist militant targets.

Western powers are pushing Libya's factions to back a U.N.-brokered national unity government to join forces against Islamic State militants, but the agreement faces major resistance from several factions on the ground.

For more than a year, an armed faction called Libya Dawn has controlled Tripoli, setting up its own self-declared government, reinstating the former parliament and forcing the recognized government to operate in the east of the country.

Western officials say forming a united government would be the first step in Libya seeking international help to fight against Islamic State, including training for a new army and possible air strikes against militant targets.

(Reporting Ayman El Sahli in Misrata, Hani Amara in Tripoli and Aziz El Yaakoubi in Rabat; Writing by Aidan Lewis and Patrick Markey; Editing by Giles Elgood and Catherine Evans)