A Taliban suicide bomber dressed as a labourer blew himself up at the NATO air base at Bagram north of the Afghan capital Kabul today, killing four Americans and wounding at least 17 people in one of the bloodiest attacks against US forces since US President Barack Obama took office.

Two US military service members and two US contractors were killed, and 16 other US service members were wounded, along with a Polish soldier who was part of the NATO mission, US Defense Secretary Ash Carter said in a statement.

Waheed Sediqqi, spokesman for the Parwan provincial governor, said the bomber managed to enter the heavily protected site, and was standing in a queue with Afghan labourers when he detonated a suicide vest.

"For those who carried out this attack, my message is simple. We will not be deterred in our mission to protect our homeland and help Afghanistan secure its own future," Mr Carter said.

It was the deadliest attack on US soldiers in the country since a suicide bomber on a motorcycle killed six American troops on patrol near Bagram in December 2015.

Mr Carter said the Pentagon will investigate today’s attack to determine what steps could be taken to improve protection for the base.

The attack, which was claimed by the Taliban, underlines the foreign policy challenge that will face US President-elect Donald Trump when he takes office in January.

Mr Obama had originally hoped to have all US forces out of the country by the end of his term, but was forced to abandon that goal as Afghan forces struggled to contain the Taliban insurgency.

Under current plans, 8,400 US troops will remain as part of the Resolute Support operation and a separate US counter-terrorism mission after Mr Obama decided to slow down a planned reduction of the force, leaving it to his successor to decide future strategy.

The attack follows a suicide attack on the German consulate in the northern city of Mazar-i-Sharif late on Thursday night that killed four people and wounded more than 100 others. That attack was retaliation for air strikes near the northern city of Kunduz last week which killed more than 30 civilians.