Image caption US forces have been stationed at Bagram since 2001 (file image)

Four US soldiers have been killed in Afghanistan, hours after the US announced direct talks with the Taliban.

A spokesman for the Taliban said the militant group was behind the attack at Bagram airbase.

Bagram, near the Afghan capital Kabul, is the largest military base for US troops in Afghanistan.

A condition for the talks, due to begin on Thursday in Qatar, was for the Taliban to renounce violence.

The soldiers were killed by "indirect fire" from insurgents at the airbase, US officials said.

Taliban spokesman Zabihullah Mujahid said the militants had launched two big rockets at Bagram.

The BBC's Jonathan Beale says the attack is a reminder that a ceasefire has not been made a precondition to the talks, scheduled to start on Thursday.

It also highlights the difficulties that may dog the negotiations with an insurgency which is far from unified, our correspondent adds.

Trust 'low'

In comments made before the news of the attack emerged, US President Barack Obama said the announcement of talks was an "important first step toward reconciliation".

The talks are set to take place in Doha, Qatar, where the Taliban have just opened their first official overseas office.

US officials said prisoner exchanges would be one topic for discussion with the Taliban, but the first weeks would mainly be used to explore each other's agendas.

Afghan President Hamid Karzai said his government was also sending delegates to Qatar to talk to the Taliban.

Also on Tuesday, Nato handed over responsibility for security for the whole of the country to Afghan security forces.

International troops are to remain in Afghanistan until the end of 2014, providing military back-up when needed.

As well as renouncing violence, other conditions of the talks are that the Taliban break ties with al-Qaeda and respect the Afghan constitution - including the rights of women and minorities.

Media playback is unsupported on your device Media caption President Obama: "We don't anticipate this process will be easy or quick, but we must pursue it in parallel with our military approach"

Talks between President Karzai's High Peace Council and the Taliban are due to follow a few days after those between the US and the Taliban, officials say.

The level of trust between the Afghan government and the Taliban is described as "low".

In the past, the Taliban have always refused to meet President Karzai or his government, dismissing them as puppets of Washington.

Masoom Stanekzai, secretary of the High Peace Council, would not give a specific date for their talks but said they would take place "within days".

US officials stressed that this was the first step on a very long road, adding that there was no guarantee of success.

'Peaceful solution'

After opening the "political bureau" in Doha on Tuesday alongside Qatari officials, Taliban representative Mohammed Naeem told reporters the group wanted good relations with Afghanistan's neighbours.

"We support a political and peaceful solution that ends Afghanistan's occupation, and guarantees the Islamic system and nationwide security, a Taliban statement said.

The BBC's Paul Adams in Washington says these were key statements that US officials were expecting to hear.

Media playback is unsupported on your device Media caption Former Afghan diplomat Masood Aziz: "Pakistan is an important part of the negotiation process"

Pakistan, which was involved in background talks for the opening of the Taliban's Doha office, said it was "ready to continue to facilitate the process to achieve lasting peace in Afghanistan in accordance with the wishes of the Afghan people".

A US official said the militant Haqqani network would also be represented by the Taliban in Doha.

However, the senior US and Nato commander in Afghanistan, Gen Joseph Dunford, said: "All I've seen of the Haqqani would make it hard for me to believe they were reconcilable."

President Karzai has expressed anger at previous US and Qatari efforts to kick-start the peace process without properly consulting his government, reports the BBC's Bilal Sarwary from Kabul.

There is also concern within the presidential palace that the Taliban will use the office in Qatar to raise funds, adds our correspondent.

The US has never held direct talks with the Taliban, but did begin preliminary negotiations in Qatar last year. However, the Taliban suspended those talks, citing US efforts to involve the Afghan government as a key stumbling block.

In Afghanistan itself on Tuesday, a ceremony in Kabul marked the handover of responsibility for security from the Nato-led International Security Assistance Force (Isaf) to the Afghan government for the first time since the Taliban were ousted in 2001.