Afghan villagers wait for customers to sell their agriculture products on the outskirts of Bagram. (Massoud Hossaini/Associated Press)

The large U.S. military base that dominates this village 30 miles north of Kabul was shut tight as a drum Sunday, with no Afghan workers allowed inside in the wake of a suicide bombing the day before.

The U.S. Embassy also shut down except for emergency services for the first time since the fall of the Taliban in 2001, in what officials called a temporary precautionary measure.

Hundreds of Afghans normally work at the sprawling military base, in the kitchens and laundry and on cleaning and construction crews. But after an attacker, identified by Afghan officials as a base worker, managed to kill four Americans and wound 17 others inside the compound, the gates were shut.

American officials have released few details of the attack and no information about the victims other than their nationalities, but Afghan security officials said Sunday that they had identified the attacker as a poor local laborer and former Taliban fighter. They said he had worked at the base “for some time” after formally returning to civilian life through a government reintegration program. 

Experts and officials in Kabul worried that the attack — only the second time a suicide bomber has penetrated a U.S. military compound during the war — could reinforce American concerns about troop safety and lead the incoming Trump administration to pull out the remaining 10,000 U.S. service members in the country.

The bombing came two days after Taliban insurgents rammed a suicide truck into the German consulate in the northern city of Mazar-e Sharif. All consulate staffers were safely evacuated, but the powerful blast, followed by heavy gunfire from Taliban fighters, killed four Afghans and wounded 128. A Taliban spokesman said it was in retaliation for a deadly U.S. airstrike in Kunduz the previous week. 

In addition to closing Bagram to outside traffic, U.S. officials said that all U.S. and allied military facilities were adding extra security measures and fortifications. The temporary closing of the U.S. Embassy, State Department officials said in a tweet, was because of a “serious threat of violence, kidnapping and hostage taking.”

American officials also warned last week that insurgents were planning to attack the Serena Hotel, a fortified luxury establishment in Kabul, and a guesthouse in an affluent area of the city. The Serena was invaded in 2014 by Taliban gunmen who shot and killed nine civilians.

The Bagram base houses about 14,000 Americans, both military service members and private contractors, and serves as one of two major hubs for American military traffic in the country. It is heavily guarded but surrounded by a cluster of thriving villages and near a busy highway corridor in Parwan province. The region, which supplies most of the low-level workers who enter each morning and leave each evening, depends heavily on the base for economic support.

Taliban statements Saturday named the bomber as a Taliban member, Hafiz Mohammad Parwani, and said he had been secretly planning the attack for the past four months while working on the base. On Sunday, Parwan police officials named the attacker as Qari Nayeb Parwani and also said he had been working as a laborer at the U.S. base. They said his family members had been arrested by Afghan intelligence police.

“The identity of the bomber has become clear,” said Mohammad Zaman Mamozai, provincial police chief, in an interview. “But we do not know how he succeeded to take explosives inside the base since security is tight all the time. We are surprised that he managed to conduct such an attack.”

Residents near the base, including several who have regular jobs there, also expressed amazement Sunday that the bomber had found a way to sneak materials inside. One man said his former job was to help search Afghan workers and that each one had to undergo body searches and scans before entering.

“They check everyone with scales and instruments. You couldn’t even take a needle in there without it being found,” said the 23-year-old worker, who gave his name as Habibullah. “There is no way an ordinary person could carry explosives inside. They would have to fly over the wall and jump in.”

With the base on total lockdown, Afghan workers said they had no idea when they would be allowed back. “Nobody sent us a message, but the gate is shut and nobody can go in,” said a cafeteria worker who gave his name as Shamarai. 

Several residents and storekeepers said that Bagram has been a good provider of business and security over the years but that the area has become more dangerous lately, with armed robbers and insurgents operating there. Afghan officials said Taliban groups are active in several areas of Parwan, once a stronghold of the main anti-Taliban militia.  

Bagram, the largest and best-known U.S. base in Afghanistan, has always been a high-priority target for the Taliban, and it has been attacked many times. In December, a suicide bomber riding a motorcycle killed six American service members patrolling outside the base. In 2007, a bomber struck an entry point to the airfield, killing two Americans and 21 others.

The U.S. military has suffered about 2,400 fatalities since 2001, when the Taliban regime was overthrown and later regrouped as an insurgency against the Western-backed civilian government.

In Saturday’s early-morning attack, the bomber detonated on a sidewalk near an exercise area where a group of men were getting ready to go running, U.S. military officials said. Other reports said there was a special race planned that day. The Taliban spokesman said the bomber had targeted a “sports ground” where “more than 100 military officers, important people and soldiers were busy exercising.”

Sayed Salahuddin and Sharif Walid contributed to this report.