TIMBUKTU, Mali — When the Islamist militants came to town, Dr. Ibrahim Maiga made a reluctant deal. He would do whatever they asked — treat their wounded, heal their fevers, bandage up without complaint the women they thrashed in the street for failing to cover their heads and faces. In return, they would allow him to keep the hospital running as he wished.

Then, one day in October, the militants called him with some unusual instructions. Put together a team, they said, bring an ambulance and come to a sun-baked public square by sand dunes.

There, before a stunned crowd, the Islamist fighters carried out what they claimed was the only just sentence for theft: cutting off the thief’s hand. As one of the fighters hacked away at the wrist of a terrified, screaming young man strapped to a chair, Dr. Maiga, a veteran of grisly emergency room scenes, looked away.

“I was shocked,” he said, holding his head in his hands. “But I was powerless. My job is to heal people. What could I do?”