Taliban bombers attacked a heavily fortified guesthouse used by Westerners in Kabul on Wednesday, announcing the start of their annual "spring offensive" in defiance of assertions from US President Barack Obama during a visit to Afghanistan that the war was ending.

Seven people were killed after attackers dressed in burqas detonated a suicide car bomb and clashed with guards at the "Green Village" complex of guesthouses used by the European Union, the United Nations and aid groups, officials said.

The attackers' ability to penetrate a tightened security cordon in the capital raises fresh concern about the resilience of the insurgency on the anniversary of Osama bin Laden's death as NATO winds down its combat presence in the next two years and hands over responsibility for security to Afghan forces.

The Taliban said the assault was a riposte to Obama, who just hours earlier signed a new partnership pact set to govern Afghan-US relations after 2014.

In an election-year address, Obama presented himself as a commander-in-chief capable of ending two long wars, following the US troop withdrawal from Iraq, and of crushing Al-Qaeda, and tried to conjure up a new dawn for a US public exhausted by conflict and recession.

"This time of war began in Afghanistan, and this is where it will end," Obama said, recalling a decade-long "dark cloud of war" after bin Laden plotted the September 11 attacks in 2001.

"Yet here, in the pre-dawn darkness of Afghanistan, we can see the light of a new day on the horizon," said Obama, seeking a second White House term later this year.

Obama flew into Kabul in secret in the dead of night and signed a deal with President Hamid Karzai, cementing 10 years of US aid for Afghanistan after NATO combat troops leave in 2014.

"We look forward to a future of peace. We're agreeing to be long-term partners," Obama said at Karzai's palace. The US president left after six hours on the ground. About two hours later, the Green Village assault began.

Police said suicide attackers wearing burqas struck at 6:15 am (0145 GMT), blowing up a car bomb, then clashing with guards. The interior ministry said seven people were killed, at least six of whom were Afghans.

There were three attackers, the ministry said, one in the suicide car bomb and two who penetrated the complex itself. One blew himself up with his explosive vest while the other was shot dead by security forces.

Mangled bodies were seen lying in the road after the attack, which left two vehicles completely destroyed and blew the windows out of a nearby school.

Kargar Noorughli, spokesman for the health ministry, said 18 people were wounded and eight admitted to hospital, including one in a critical condition and "several children".

"It is a message to Obama that he and his forces are never welcomed in Afghanistan and that we will continue our resistance until all the occupiers are either dead or leave our country," Taliban spokesman Zabiullah Mujahid told AFP.

The militia later announced that its spring offensive, code-named Al-Farouq, would from Thursday target "foreign invaders, their advisors, their contractors, all those who help them militarily and in intelligence".

Wednesday's assault, which lasted more than three hours, came just over two weeks after one of the largest attacks in Kabul, where militants targeted government offices, embassies and foreign bases.

Karzai said the US pact was no threat to any third country and he hoped it would lead to stability in the region.

Neighbouring Pakistan has long been seen as a source of instability in Afghanistan, and its relationship with both Kabul and Washington remains mired in mistrust a year after bin Laden was found and killed by US commandos on its soil.

The White House said the US-Afghan pact sees the possibility of American forces staying behind to train Afghan forces and pursue the remnants of Al-Qaeda for 10 years after 2014.

The deal was concluded just over two weeks before a NATO summit in Chicago, but it does not cover the crucial issue of the status of any US troops remaining in Afghanistan.

Instead it commits Washington to specific troop or funding levels for Afghanistan, though is meant to signal to US foes that despite ending the longest war in US history, Washington intends to ensure Afghanistan does not revert to a haven for terror groups like Al-Qaeda.

But after a war that has cost the lives of nearly 3,000 US and allied troops, thousands of Afghans and cost hundreds of billions of dollars, Afghanistan's future is deeply uncertain.

Yet US troops could be fighting for two more years, and some could remain in danger for a decade after that.

Obama bluntly told US soldiers that "some of your buddies are going to get injured, some of your buddies may get killed".

A Pentagon report issued Tuesday said that insurgent sanctuaries in Pakistan and corruption pose "long-term and acute challenges".

About 87,000 US troops and 44,000 other international forces are deployed in Afghanistan along with 344,000 Afghan army and police, the report said.