Gunmen launched a pre-dawn raid on a military compound in Kabul on Monday, in an ongoing assault that has caused multiple casualties and is the third major attack in the city in recent days.
At least two soldiers have been killed and 10 wounded in a fierce gun battle with several attackers near the Marshal Fahim military academy, defence ministry spokesman Dawlat Waziri said.
"An Afghan army battalion has come under attack this morning. The attackers wanted to breach the battalion," Waziri said.
"One bomber detonated himself and another bomber was detained by our forces. Three others were killed and one other is resisting our forces," he added.
Officials said the attack was on an army battalion near the academy where high-ranking officers are trained and which was initially identified as the target.
An Afghan security source said the gunmen had not managed to enter the heavily fortified compound, which is on the western outskirts of the city.
Witnesses told AFP they heard several explosions and gunfire at around 5:00 am (0030 GMT).
An officer inside the training academy said he heard an explosion followed by an exchange of gunfire.
Kabul police spokesman Basir Mujahid confirmed to AFP there had been rocket and gunfire.
In October a Taliban suicide bomber killed 15 Afghan army trainees as they travelled home from the Marshal Fahim academy.
There was no immediate claim of responsibility for the latest raid, which comes days after a Taliban suicide attacker driving an explosives-packed ambulance blew up in a crowded area of the city, killing and wounding hundreds.
At least 103 people were killed and 235 wounded in Saturday's lunchtime attack, one of the worst bombings in the city in recent years, which was followed by a national day of mourning in the war-weary country.
The government has blamed the Taliban-affiliated Haqqani Network, which Afghan and Western officials suspect of involvement in at least some of the recent attacks in the capital.
Monday's ambush came as both the insurgents and the Islamic State group have escalated their attacks on Kabul, turning it into one of the deadliest places in Afghanistan for civilians.
On January 20, Taliban insurgents stormed Kabul's landmark Intercontinental hotel and killed at least 25 people, the majority foreigners, in an ordeal lasting more than 12 hours.
But there is still confusion over the true toll from that attack with conflicting figures given by officials and Afghan media reporting higher numbers
Kabul remains on high alert as the city braces for further attacks. Security warnings sent to foreigners in recent days said IS militants were planning to attack supermarkets, hotels and shops frequented by foreigners.
Several foreign organisations, including humanitarian groups, are reassessing their operations after a particularly deadly week in the country.
IS fighters attacked Save the Children's office in Afghanistan's east on Wednesday that officials said killed five people and wounded another 26.