“The majority of our soldiers were offering Friday prayers” at the time of the assault, the Afghan Defence Ministry said in a statement.
“Over 100 Afghan army forces were martyred and wounded,” the statement said.
The gunfight lasted for several hours as two of the attackers blew themselves up and seven others were later killed in the assault near Mazar-i-Sharif city. The attackers targeted soldiers at a mosque and dining facility.
“They (soldiers) were young recruits who had come for training,” a military official told AFP.
General John Nicholson, the top US commander in Afghanistan, praised Afghan commandos for bringing the “atrocity to an end”.
Afghan security forces, beset by killings, desertions and non-existent “ghost soldiers” on the payroll, have been struggling to beat back insurgents since US-led NATO troops ended their combat mission in December 2014.
The attack is the latest in a string of deadly assaults against an Afghan military sites, which underscores rising insecurity in the war-torn country as it braces for an intense fighting season in the spring.
In February, Nicholson told the US Senate Armed Services Committee in Washington that he needed “a few thousand” more troops to help train and assist the Afghan forces.
The US has around 8,400 troops in the country with about another 5,000 from NATO allies assisting a much larger Afghan force in the war against the Taliban and other Islamist militants.
The last major attack against a military site was in early March when gunmen disguised as doctors stormed the Sardar Daud Khan hospital — the country’s largest military hospital — in Kabul, killing dozens.
(With inputs from agencies)