The Chief of Defence Force, Lieutenant General Rhys Jones said: "He, with his colleagues, was attempting to free hostages trapped in the council buildings following the attack.
"His is the first loss of life in action the NZSAS group has suffered in Afghanistan. Their work is always dangerous; they are brave men who trained to do all they can to serve New Zealand."
General Jones said next of kin were told late last night of the death.
"I'm sure I speak for all New Zealanders when I say how saddened we are to hear news of the death of one of our own in Afghanistan."
British Prime Minister David Cameron condemned the "cowardly attack" and said he had spoken to Mr Key to thank him for the role New Zealand's forces had played in defending the compound.
Mr Cameron praised the "incredibly brave and hard-working New Zealand special forces".
Britain's Foreign Office said all insurgents involved in the attack were killed.
The attack started when one suicide bomber detonated an explosives-laden car outside the British Council compound.
Afghan security forces sent to the scene said at least three attackers fought from a secure bunker inside the compound with rifles and rocket-propelled grenades.
An Afghan policeman said that the insurgents wrestled weapons and ammunition from compound guards.
A police official said he counted five suicide bombers. One detonated the car outside the compound, one set off an explosion inside and at least three more got inside the compound on foot.
Hours into the battle, two more blasts occurred, part of the building was on fire and smoke covered the areas.
Ambulances and at least one helicopter ferried casualties to hospitals.
The Daily Telegraph said it was understood that Afghan and New Zealand soldiers led the operation to end the attack, with assistance from British, United States and French troops.
Loud explosions and long bursts of gunfire could be heard from within the building, circling helicopters released counter-missile flares and a medical evacuation helicopter briefly landed and then departed again 50m from the site.
The walled compound of the British Council - the UK government's cultural and educational mission - is in an upscale residential area of the capital.
British soldiers rushed to the compound after the attack, joining Afghan police, soldiers and the New Zealand Special Air Service.
The Guardian website also reported that journalists were ordered to stop taking photos when what appeared to be the New Zealand soldier was stretchered out of the building and loaded on to a medevac helicopter.
Elite troops expected to leave in 7 months
New Zealand's SAS troops have been in Afghanistan since December 2001.
The current deployment was due to end last March but under pressure from the soldiers themselves, the Government agreed to extend the mission until March next year.
Last month, Prime Minister John Key said it was "unlikely" the deployment would go beyond then, but refused to rule it out.
The 38 Special Air Service soldiers are among the 196 New Zealand troops in Afghanistan.
Most of them provide security for the provincial reconstruction force in Bamiyan province.
The SAS soldiers are based in Kabul, where they train an Afghani force that responds to incidents including terrorist attacks.
The most celebrated SAS soldier is Corporal Willie Apiata, who was awarded the Victoria Cross. He received it in July 2007 for bravery during the Afghanistan conflict in 2004, after carrying a wounded comrade under fire to safety.
Corporal Apiata returned to Afghanistan with the SAS in 2009 and was famously photographed leaving a firefight in Kabul.
Last month, SAS troops intervened in a gunfight with Taleban insurgents who had stormed the home of a close adviser to President Hamid Karzai.
In June, two SAS soldiers were injured during an assault by insurgents on the Inter-Continental Hotel in Kabul.
Two New Zealand soldiers have been killed in Bamiyan province. Lieutenant Timothy O'Donnell died in August last year after his convoy was ambushed. The second to be killed was Private Kirifi Mila, when the Humvee he was in rolled down a cliff in February this year.
NZ Army combat deaths since 1990:
* 24 July, 2000: Private Leonard Manning, in East Timor.
* 4 August, 2010: Lieutenant Tim O'Donnell, in Afghanistan.
* 19 August, 2011: Unidentified SAS soldier, in Kabul.
- NZ HERALD, AP