The attackers "dressed as women ... walked towards the guards at the NDS gates, pretending to submit an application paper" before one set off his suicide belt, the statement said.
Three of the six attackers fled. Two were killed by Afghan soldiers and another shot dead by police, the NDS statement said.
"The other attacker, the sixth person, escaped towards the city and was later identified and fired at by police near a police station ... after which he detonated, killing two police," the statement said.
Officials said all six men were killed before reaching their targets, though Zabiullah Mujahid, a Taliban spokesman, said that up to 15 fighters had been involved in the attack.
Five security personnel were killed and four children, a woman and a police officer were wounded.
Gardez was put under a curfew before Afghan authorities gained "full control over the city", said Azizuddin Wardak, the provincial police chief.
Two suicide attackers on a motorbike carrying AK-47s and a rocket-propelled grenade were killed in an attempted attack on the city's airport, also a military base, in Jalalabad in Nangarhar province, said Mohamamd Ayub Salangi, the provincial police chief.
A police officer was also killed.
Mujahid, a Taliban spokesman, said the group was behind both attacks.
Al Jazeera's Zeina Khodr, reporting from the capital, Kabul, said: "They are striking at symbols of Afghan power.
"This resembles other assaults that the Taliban has carried out in recent months - less than two months ago in Khost in the southeast, they laid siege to the city for almost 10 hours."
Khost, which is 70km east of Gardez, is a key area of operations for fighters associated with a network run by Sirajuddin Haqqani, a pro-Taliban leader.
Violence has surged across Afghanistan since thousands of US Marines and British troops launched major new offensives in southern Helmand province.
July has already become the deadliest month of the war for both US troops and foreign forces as a whole in Afghanistan.
The attacks also come ahead of Afghanistan's elections, scheduled for August 20, when Hamid Karzai, the Afghan president, will stand for re-election despite criticisms about security and corruption.
But the recent increase in violence has fuelled fears that Afghan and foreign forces will not be able to protect voters.
Khodr reported: "Even the Afghan election commission says that 30 per cent of those polling stations may not be secure.
"Interior ministry figures say that 124 out of the 364 districts are deemed unsafe."