KABUL, Afghanistan — Militants stormed Afghan government offices in Kabul on Monday after setting off a car bomb, and officials said at least 43 people were killed.

The attack lasted at least five hours and shattered a period of relative calm in the Afghan capital, which over the years has been subjected to deadly and audacious assaults by militants opposed to the American-backed government.

It also came less than a week after President Trump reportedly instructed the Pentagon to prepare for the withdrawal of about half the American military contingent deployed in Afghanistan, an abrupt shift in policy that caught Afghan officials by surprise.

The attack began late in the afternoon as employees were leaving an area that houses offices belonging to the Afghan Ministry of Public Works and the administration dealing with pensions for the families of people killed and disabled in Afghanistan’s long war.