The soldiers were leaving the town of Suleiman Bek to go on leave, but were stopped by militants who killed them, official Talib Mohammed al-Bayati said.
Four other soldiers were wounded in the shooting on the highway out of the town, he said.
No one immediately claimed the attack, but Sunni militants, including those linked to the powerful Islamic State of Iraq and the Levant, have in the past targeted the security forces.