The insurgents launched their attacks before dawn, firing rifles, machine guns, rockets, and rocket-propelled grenades on the two U.S. bases.
Coalition forces said they were able to repel the attacks on the sprawling Forward Operating Base Salerno and nearby Camp Chapman, in Afghanistan's eastern Khost Province close to the border with Pakistan.
NATO said at least 21 insurgents were killed. According to the alliance, four NATO soldiers were wounded but none were killed. Local police said they, too, had suffered no casualties.
Khost provincial police chief Abdul Hakim Ishaqzai put the death toll at 24.
"According to the latest information we have, 24 enemies were killed in the battle and their bodies are still on the ground. We captured five other attackers."Ishaqzai told RFE/RL's Radio Mashaal.
The Taliban were quick to claim responsibility, saying about 30 fighters -- including suicide bombers -- were involved in the assaults. Taliban spokesman Zabiullah Mujahid claimed 18 foreign soldiers had died in the battle.
NATO said the dead insurgents, some of whom wore U.S. Army uniforms, were members of the Haqqani network, an Al-Qaeda-linked group accused of launching frequent raids across the border from Pakistan. It said a top Haqqani explosives expert, Mudasir, was killed in the battle.
Khost police chief Ishaqzai said the insurgents also tried to attack the offices of the governor and provincial police headquarters but were driven away. Foreign and Afghan troops, he said, prevented a "major catastrophe."
The raids were the latest in a string of attacks on foreign military bases and Afghan government buildings in the area, a hotbed of Taliban activity.
Seven Central Intelligence Agency (CIA) officers were killed by a suicide bomber in Chapman base last December, the second-most deadly attack in CIA history.
RFE/RL's Radio Mashaal contributed to this report