Authorities blamed remnants of the Shining Path communist guerrilla group, which was largely crushed in the 1990s but still has members hiding in the jungle.
The three soldiers and a driver were killed yesterday as they were taking forces to guard voting stations in the central Junin region.
"Special forces and supporting aircraft were sent to take control of the area and remove the military personnel that still remains in place," the Joint Command of the Armed Forces said in a statement.
In a second attack, they targeted a military ship on the Apurimac River in the south, wounding two soldiers, authorities said.
More From This Section
President Ollanta Humala condemned the "insane" violence.
"Terrorism and those who collude with it have no place in our society or in our family," said Humala.
Mariano Cucho, the head of the National Office of Electoral Processes, insisted that "this attack will not tarnish the elections."
Some 23 million Peruvians are called to vote today for a new president and members of congress.
Around 69,000 people were killed between 1980 and 2000 in the conflict with the Shining Path, according to the country's Truth and Reconciliation commission.
"Peru has lived through these violent periods and we are working to bring peace to the country," Humala told a news conference.
"All these demented acts do is unite the Peruvian people more."
Authorities say remnants of the guerrilla group have joined forces with drug gangs and remain active in the remote mountains and jungles.