He said the National Liberation Army (ELN), Colombia`s second-biggest rebel group, was behind the attack.
President Juan Manuel Santos vowed retaliation against the attackers.
On Sunday, Mr Santos had said the election had been "the most peaceful and least violent in decades".
Eleven of those killed were soldiers, while the other was a police officer, Mr Villegas said.
Six other people, among them poll workers and a local guide, were missing, he added.
Colombia`s government is locked in talks with another rebel group, the Revolutionary Armed Forces of Colombia, or Farc, to end more than five decades of violence.
Late last month, the two parties reached agreement on how to punish human rights abuses committed during the conflict - a detail seen as key to a lasting peace deal.
The Farc has called several times for the ELN to join their peace talks.
Occasional attacks by Farc rebels have occurred despite negotiations taking place in Havana. In May, it ambushed and killed 11 soldiers after briefly suspending its ceasefire.
A month later, rebels killed three police officers and cut off power to close to 500,000 people.