ABUJA, Nigeria — More than four years ago, Islamist militants from Boko Haram invaded the town of Bama in northeastern Nigeria, setting up a new headquarters there and sending tens of thousands of people fleeing for their lives.

For years many of those residents of Bama lived in squalid camps or other temporary housing as clashes between fighters and the military destroyed their town. Finally, earlier this year the government told residents that it was safe to return.

New homes and new schools — a whole new Bama — awaited as part of a state-sponsored rebuilding program, officials assured them. Many of Bama’s residents leapt at the chance to get their lives back to normal. In April, the government escorted 3,600 of them back home.

But when people arrived in Bama many found homes that were mere shells, with unfinished interiors and no plumbing. Only a handful of schools were functioning, and they became badly overcrowded. The main hospital was poorly staffed and didn’t have enough working refrigerators to keep medicine from spoiling. There were so few toilets in town that people were defecating in the open.