MAIDUGURI, Nigeria—At the northern edge of this city’s sprawling military base, a vast field of churned soil conceals the hidden toll of a deadly offensive by the allies of Islamic State.

After dark, the bodies of soldiers are covertly transported from a mortuary that at times gets so crowded the corpses are delivered by truck, according to Nigerian soldiers, diplomats and a senior government official. The bodies are laid by flashlight into trenches dug by infantrymen or local villagers paid a few dollars per shift.

“Several...