TRIPOLI, Aug 16 (Reuters) - Heavy fighting erupted on Saturday between rival militias in Libya's capital, hours after the new U.N. special envoy said he planned to visit Tripoli as early as next week to try to broker a ceasefire.

Gunfire and shelling with Grad rockets and artillery guns could be heard from the early morning near the airport and several residential parts of Tripoli.

Spanish diplomat Bernardino Leon, who is due to start his job officially on Sept. 1, aims to end fighting between brigades from Misrata and fighters allied to the western town of Zintan, whose rivalries erupted a month ago into the worst clashes since the 2011 uprising that ousted Muammar Gaddafi.

The battles, which involve brigades of former rebels who once fought Gaddafi together, have forced the United Nations and Western governments to evacuate their diplomats, fearing Libya is sliding into civil war.

Most of the fighting has raged over the international airport in Tripoli, which fighters from Zintan have controlled since sweeping into the capital during the 2011 war.

Libya's fragile government still has no national army and often put former rebels on the state payroll as semi-official security forces as a way to co-opt them into the new state.

But the heavily armed rival brigades are allied with competing political factions and are often more loyal to their region, city or local commanders than to the central government.

A separate battle in the eastern city of Benghazi has complicated Libya's security, with an alliance of Islamist militants and ex-rebels forcing the army out of the city.

Three years since Gaddafi's one-man rule ended, Libya's fragile efforts towards democracy are close to chaos. The month of fighting in Tripoli and Benghazi has further polarised the political factions and their militia allies. (Reporting by Reuters reporters in Libya; Writing by Ulf Laessing; Editing by Sonya Hepinstall)