"The prime minister's car was hit by bullets when armed men opened fire as it was leaving an area where a session of parliament was held" in the eastern city of Tobruk, said Hatem el-Ouraybi.
"The prime minister was not hurt, but one of his bodyguards was wounded," he told AFP on the phone.
"It was an assassination attempt, and the prime minister survived it," he added, without being able to identify the assailants.
Wracked by bloody turmoil after a 2011 uprising toppled and killed dictator Moamer Kadhafi, Libya has had two governments and parliaments since an Islamist-backed militia alliance seized Tripoli last August.
Tuesday's shooting came after a meeting of the internationally recognised parliament at its headquarters in Tobruk.
Lawmaker Faraj Abu Hashem said the gunmen had attempted to storm the building but were driven back.
"Members of the government and the prime minister left immediately as gunmen tried to storm the parliament... but forces prevented them from entering."
Libya has seen near daily attacks on security forces, particularly in and around the eastern city of Benghazi, cradle of the anti-Kadhafi revolt.
In January last year, Libya's then interior minister said he escaped unharmed from an assassination attempt in Tripoli, three weeks after deputy industry minister Hassan al-Droui was shot dead in Kadhafi's home town of Sirte.
Get Breaking news, live coverage, and Latest News from India and around the world on NDTV.com. Catch all the Live TV action on NDTV 24x7 and NDTV India. Like us on Facebook or follow us on Twitter and Instagram for latest news and live news updates.