DZALANYAMA FOREST RESERVE, Malawi — Out of desperation, soldiers were dispatched to the national forest here last year to defend the capital, Lilongwe, less than 30 miles away. Their mission was not to save it from an invading force, but to keep water flowing to its taps.

For years, wood charcoal burners had been destroying this forest, the catchment basin for the Lilongwe River, the source of the capital’s water. Fewer trees mean the ground is less able to absorb water in the rainy season and gradually surrender it the rest of the year. With the supply reaching the capital dwindling and increasingly turbid, and with the El Niño drought spreading across Malawi and the rest of southern Africa, the capital was under imminent threat.

“We’ve always known we’d have the problems we’re facing now,” said Alfonso Chikuni, the chief executive of the state-owned Lilongwe Water Board. After the board agreed to bear the cost of the deployment, the army ordered a company of soldiers to the Dzalanyama Forest in February 2015 to save the trees.

The order came too late.

Two months ago, with the water supply increasingly squeezed by the drought and rebellion in the forest, Mr. Chikuni started rationing in the capital, leaving customers bereft for half the week.