KABUL (Reuters) - A Taliban suicide bomber dressed as a laborer blew himself up at the NATO air base at Bagram north of the Afghan capital Kabul on Saturday, killing four Americans and wounding at least 17 people in one of the bloodiest attacks against U.S. forces since President Barack Obama took office.

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

“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,” Carter said.

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

Carter said the Pentagon will investigate Saturday’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 U.S. President-elect Donald Trump when he takes office in January.

President Barack Obama had originally hoped to have all U.S. 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 U.S. troops will remain as part of the Resolute Support operation and a separate U.S. counter terrorism mission after Obama decided to slow down a planned reduction of the force, leaving it to his successor to decide future strategy.

Waheed Sediqqi, spokesman for the Parwan provincial governor, said the bomber managed to enter the heavily protected site, the largest U.S. base in Afghanistan, and was standing in a line with Afghan laborers when he detonated a suicide vest.

Slideshow ( 5 images )

The NATO-led Resolute Support mission response teams at the airfield were treating the wounded and investigating the incident.

It 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.

The Taliban’s spokesman, Zabihullah Mujahid, said Saturday’s attack, which he said had been planned for four months, had caused heavy casualties, killing 23 Americans and wounding 44. The movement often exaggerates the number of casualties caused by its operations.