KABUL (AFP) – An Afghan army infiltrator opened fire inside the defence ministry in Kabul on Monday, killing two soldiers and wounding seven in an audacious strike on the heart of government claimed by the Taliban.

The attack, which the militants said was aimed at France's visiting defence minister, was the third major assault on Afghan security targets in four days and one of the worst security breaches in years.

"A person in Afghan army uniform opened fire on his comrades, killed two soldiers, injured seven others, then was targeted himself and was brought down," Afghan army spokesman General Mohammad Zahir Azimi told AFP.

After his death the gunman was found to be wearing a suicide vest, he said.

A military source speaking on condition of anonymity told AFP that three insurgents had managed to enter the building, which faces President Hamid Karzai's palace, and all were killed.

The ambush inside the tightly-secured compound is thought to be the most high-profile security breach since a failed attempt on Karzai's life in 2008.

French Defence Minister Gerard Longuet is currently on a visit to Afghanistan but was not in the building at the time.

A French official stressed they had seen "no evidence" that the attack was an attempt to kill Longuet, while his office said he was at Bagram airfield, more than 40 kilometres (24 miles) away, at the time.

An Afghan official, also speaking anonymously, said the building had been evacuated, the incident was over and an investigation was under way.

Taliban spokesman Zabihullah Mujahid told AFP that Longuet was the target.

"The reason for conducting this attack is the invasion of Afghanistan by the French military," he said, adding that it was not carried out over the controversial banning of the Islamic full-face veil in France.

There are some 4,000 French troops stationed in Afghanistan as part of a roughly 130,000-strong NATO-led international force.

The Islamist militia are known frequently to exaggerate claims in relation to their attacks.

Afghan Defence Minister Abdul Rahim Wardak was not injured in the attack, a Western security source said, but it is thought that the suicide bomber was shot dead close to the minister's office.

The incident comes amid a string of serious attacks on pro-government security forces in recent days by insurgents wearing military and police uniforms.

On Friday the police chief of Kandahar province in southern Afghanistan, seen as a key battleground in the war, was killed in the police headquarters by an attacker in police uniform.

And on Saturday, five international and four Afghan troops died when a member of the Afghan National Army blew himself up at an army base in Laghman province, eastern Afghanistan.

That was the deadliest single attack against foreign forces since December, while Saturday was the worst day for international troops in Afghanistan since June last year, with a total of eight soldiers killed.

Elsewhere in Afghanistan on Monday, six police officers were killed by a roadside bomb in Ghazni province, central Afghanistan, in an attack also claimed by the Taliban.

"The police officers were coming to Ghazni police headquarters from Khugyani district when they were hit by a roadside bomb," Delawar Zahid, the provincial police chief said.

"Their vehicle was totally destroyed, and no one survived."

In three months' time, Afghan forces are due to start taking control of security from foreign troops in eight more peaceful areas of the country, allowing for limited international withdrawals.

Afghan forces are due to take full control of security in their country in 2014, allowing a full withdrawal of foreign combat troops.

The fighting season in Afghanistan is starting to get under way as spring arrives, and Western officials including US Secretary of State Hillary Clinton have warned it could bring some of the bloodiest fighting yet in the near ten-year war.