The Taliban claimed responsibility today for an attack in Afghanistan that killed four American troops just hours after it announced it would hold talks with the US.

The attack underscores the challenges in trying to end the violence in Afghanistan through peace negotiations in Qatar with militants still fighting on the ground.

Taliban spokesman Zabiullah Mujahid said the insurgents fired two rockets into the Bagram airbase outside the Afghan capital Kabul.

American officials confirmed the base came under attack by indirect fire - probably from a mortar or rocket - and four US troops were killed.

Five Afghan police officers were also killed at a security outpost in Helmand province by apparent Taliban infiltrators - the latest in a string of so-called "insider attacks" that have shaken the confidence of the nascent Afghan security forces.

The attacks came as the Taliban opened a political office in the Qatari capital of Doha, and announced they were ready for peace talks.

The decision was a reversal of months of failed efforts to start negotiations while Taliban militants intensified a campaign targeting urban centres and government installations across Afghanistan.

US president Barack Obama cautioned that the peace talks with the Taliban would be neither quick nor easy but opening a political office in Doha was an "important first step toward reconciliation" between the Islamic militants and the government of Afghanistan.

In setting up the office, the Taliban said they were willing to use all legal means to end what they called the occupation of Afghanistan - but they did not say they would immediately stop fighting.

American officials said US and Taliban representatives will hold bilateral meetings in the coming days. Afghan president Hamid Karzai's High Peace Council is expected to follow up with its own talks with the Taliban a few days later.

The Taliban announcement followed a milestone handover in Afghanistan earlier yesterday as Afghan forces formally took the lead from the Nato coalition for security nationwide. It marked a turning point for Nato military forces, which will now move entirely into a supporting role.

The handover paves the way for the departure of the majority of coalition forces - currently numbering about 100,000 troops from 48 countries - within 18 months.

The Nato-led force is to be cut in half by the end of the year, and by the end of 2014 all combat troops are to leave and be replaced - contingent on Afghan governmental approval - by a smaller force that would be on hand for training and advising.

It is thought that it would be a force made up of about 9,000 Americans and 6,000 allies.

Six years ago, Afghan security forces numbered fewer than 40,000, and have grown to about 352,000 today, but questions remain about whether they are good enough to fight alone.

In the Helmand attack late yesterday, five police officers who had only been on the local force for three months were killed, apparently by five of their fellow officers. The killings were blamed on Taliban infiltrators, and the suspects escaped with the victims' weapons.

In a similar attack in Helmand a week ago, six policemen were found shot dead at their checkpoint, and there have been several other such incidents in the past year, including officers poisoned while eating.

Taliban insurgents have warned they would infiltrate Afghan security forces to carry out insider attacks.

Overnight in the eastern province of Nangrahar, police ambushed Taliban fighters outside a village in the Surkh Rod district, killing four and capturing two militants. Two police officers were wounded in the fighting.

Sign up to our free newsletters

Get the best updates straight to your inbox:
Please select at least one mailing list.

You can unsubscribe at any time by clicking the link in the footer of our emails. We use Mailchimp as our marketing platform. By subscribing, you acknowledge that your information will be transferred to Mailchimp for processing.