One injured soldier, Mohammad Hussain, said: “When I came out of the mosque, three people with army uniforms and an army vehicle started shooting at us. Of course, they had some infiltrators inside the base, otherwise they would never have been able to enter.

“One of them sitting inside a vehicle had set up a machine gun at the car’s window and shot everyone in his way.”

President Ashraf Ghani flew to the area on Saturday and visited wounded troops.

US military spokesman John Thomas described the attack as a “significant” strike, but he praised Afghan commandos for bringing the “atrocity to an end”.

Relatives’ anger: Syed Anwar, BBC News, Kabul

Image caption
Jan Agah from Jowzjan province lost a nephew in the attack

There are conflicting reports about casualties. The defence ministry confirmed more than 100 soldiers had been “killed or injured” but a security official in Mazar-e Sharif told the BBC that more than 100 had died, including a top military commander.

Relatives of some of the soldiers gathered outside the base to take possession of coffins. They all questioned the security measures in place at the main entrance.

“If strict inspections had taken place, the attackers would not have passed the first gate,” said Jan Agah, from Jowzjan province. One of his nephews serving at the base died and another was injured in the attack.

The raid shows the Taliban can plan and carry out complex attacks. The militants said four of the attackers had served as soldiers for a long time and had knowledge of every corner of the base.

The base at Mazar-e-Sharif is home to the Afghan National Army’s 209th Corps, responsible for providing security to most of northern Afghanistan, including Kunduz province – which has seen heavy recent fighting.

Several German and other foreign soldiers are reported to be garrisoned there.