“All the bodies were wrapped in blankets in their beds,” Mr. Qasim said.

Hajji Ghawsuddin, a member of the village development council in Zari, said two of those who were killed were his relatives. One of them, a 40-year-old guard named Israyeel, was shot in the face. Nearly 1,000 people attended the funerals of the two men, he said.

“The gunmen — neighbors were saying there were three of them — climbed over the walls and sprayed bullets at workers who were there,” Mr. Ghawsuddin said. “Two of the workers who hid themselves in a dark room survived.”

The attackers seem to have fled the scene after a brief exchange of fire with the police, who arrived an hour after the shootings, Mr. Qasim said.

The attack came as a Taliban offensive is intensifying across Afghanistan. Balkh, long considered a safe economic hub, has endured a spike in violence in recent weeks. A Taliban attack on the provincial attorney general’s office in April left 19 people dead and more than 60 wounded.

The Zari attack was the third large episode targeting aid workers in recent months. Five workers for Save the Children were abducted in southern Oruzgan Province, and their bodies were found on April 10. In May, eight aid workers were killed in a Kabul guesthouse under circumstances that remain mysterious.

All of this has left aid workers worried about a difficult year ahead.

“There is a real difference from the previous year, an awful and real increase,” said Justine Piquemal, the director of Acbar. “We stay committed, so NGOs will stay to support the Afghan population, who is the first to suffer. However, yes, the high violence will impact our work. We have to protect our colleagues.”

The work of organizations such as People in Need is central to the National Solidarity Program, which foreign donors and local Afghans have praised as one of the success stories of a government that has otherwise struggled to establish its reach despite billions of dollars in international aid. Grants from the program have brought bridges, wells and even hydropower to many far-flung and volatile villages.