"An army checkpoint in al-Malti region between Tarhuna and Bani Walid was attacked at dawn on Saturday by an unknown group. Fifteen soldiers were killed and four others wounded," Ali Sheikhi, a military spokesman said.
The troops came under heavy fire from the gunmen who drove vehicles with mounted machine guns.
Bani Walid was a stronghold of supporters of slain Libyan dictator Muammar Gaddafi in 2011.
It is not yet clear who carried out the attack, but the government has struggled to control armed groups.
The main road to Bani Walid was closed while the incident was investigated.
According to analysts the lack of central government control over large swathes of Libya has left room for armed groups to thrive.
Much of the recent violence has been blamed on armed groups which grew out of the rebel movement behind the overthrow of ex-dictator Gaddafi during the 2011 civil war.
Military officers and other members of the security apparatus are among those who have been targeted in recent weeks.
The lack of security in Libya has been highlighted this year by clashes in the eastern city of Benghazi as protesters demanded the disbandment of militias.
Gunmen also surrounded ministries in Tripoli earlier this year demanding the sacking of officials who worked during Gaddafi's rule.
RA/HH