DIABALY, Mali — At first, the battle went well.

Boubacar Yattara, a 25-year-old Malian soldier, fed the heavy machine gun atop an armored vehicle. His unit fired on a truck full of Islamist militants, destroying it. He radioed for reinforcements, but his commanding officer had bad news. His fellow soldiers had already fallen back, beating a hasty retreat.

So Mr. Yattara did what other soldiers had done as the fighting intensified: He stripped off his uniform, waded through an irrigation canal and melted into the town’s civilian population.

“They abandoned us,” Mr. Yattara said of the other soldiers, speaking from the hospital bed where he was being treated for a concussion. “We barely escaped with our lives.”

In many ways, the battle for Diabaly was over before it even began, the latest in a long string of humiliating defeats for an army that the United States once hoped would be a model for fighting Islamic extremism in one of the most forbidding regions of the world. Instead, it is a weak, dysfunctional force that is as much a cause of Mali’s crisis as a potential part of the solution.