Aisha considers herself devoted to both Islam and the game. Illustration by Ping Zhu

Aisha got her first call from the terrorists when she was fourteen. It was 2013, and she was at home, in Mogadishu, Somalia, when an unknown number appeared on her phone. She picked up. The man on the other end told her that Islam does not allow women to play sports, or to wear shirts and pants. It was immodest and indecent, he said. His voice was harsh and menacing. He told her that he was going to kill her if she didn’t stop playing basketball. The next day, another man called to say the same thing.

Aisha changed her phone number three times, but the calls kept coming, and she became convinced that someone at the mobile-phone company was giving out her contact information. After a while, Aisha began to argue with the callers, telling them that she was going to do whatever she wanted. When they threatened to kill her, she responded that only God was permitted to be in control of people’s souls. She was just a teen-age girl, but even she knew that—unlike these supposedly pious men. Then her mother started getting calls, from men who warned that she was going to lose a daughter. Trying to appeal to her faith, they told her that basketball was haram—forbidden. Her mother was worried, and wanted Aisha to stop playing.

Aisha had first picked up a basketball only recently, but she had taken to it quickly. Her phone filled with photos and videos of the basketball player she most wanted to emulate: a famous American athlete named LeBron James. She had seen James on the Internet and found him mesmerizing. “He is black and tall and a really nice player,” she said. He was powerful and agile, endlessly clever. She wanted to have that kind of magic.

In a way, she felt destined for the game. Her mother, Warsan, had played when she was younger. Her father, Khaled, had worked as a referee in Somali basketball leagues, and she had gone to his games. “To see women and men playing, it was inspiring,” Aisha recalled. She began joining pickup games in tan-dirt lots around her house with kids who lived in her neighborhood. She didn’t know what she was doing, but she didn’t care; it was exciting just to hold a ball. “I always wanted to play basketball, but I was afraid that I wouldn’t find girls who would want to play with me,” she said. Not long after, a coach named Nasro Mohamed, a former teammate of her mother’s, asked if she was interested in playing regularly. Mohamed got Aisha together with seven other girls to start practicing.

Mogadishu was once a beautiful place, with pale, handsome government offices, mosques, and grand homes, all angling for proximity to the white beaches at the edge of the Indian Ocean. Now, after more than two decades of civil war and lawlessness, the buildings are riddled with bullet and shell holes, or crumbling from neglect, or newly built and characterless; the streets, where sand pools in the cracks, are filled with soldiers and policemen.

Aisha grew up in Suuq Bacaad, a neighborhood of low bungalows behind gates with bright, peeling paint. Her father had four wives and divided his time between them, but he managed to be with Aisha enough for her to feel loved. Her family wasn’t rich, but had enough money to get by. “My parents really worked hard to make sure that I had everything I needed,” she recalled. Aisha had two brothers and a sister, and she took it for granted that each member of the family would look out for the others. Even her neighborhood functioned like a clan: she played hide-and-seek with other children, some of whom were as close to her as siblings.

Warsan ran a café and a business that sold gold. She was tall and gentle, and never hit her children, as other mothers in the neighborhood did. She understood Aisha’s passion for basketball, because she’d once had the same need to play. Khaled supported Aisha, too, visiting her on the court and urging her to take the game seriously. Somalia has a club league, in which hundreds of girls and women play on eight teams in Mogadishu and several more in other parts of the country; the best players are recruited for the national team. “My father told me, ‘Either leave basketball or aspire to be a professional,’ ” Aisha said.

For Aisha, the best part of the day was going with her friends to a neighborhood court. In school, she was easily distracted. “I was not good with the teachers,” she said. “I never stopped talking and telling jokes. I annoyed everyone.” When she was in the eighth grade, she stopped going to school altogether. Her parents were upset; they had both gone to university and prioritized education for their children. They tried to force her to go back, but Aisha refused. “I didn’t feel like it was necessary for me to continue,” she told me. And, anyway, there was a civil war raging, and the future was impossible to predict.

Somalia ceased to be a coherent state in 1991, when its dictator, Siad Barre, was deposed by rebel militias. Barre, who had taken power in a military coup two decades before, had treated opponents brutally, but had also attempted to modernize the country. He moved to end the lineage-based clan, which traditionally defined politics in Somalia, by imposing a nationalist form of socialism. He codified a written form of the Somali language, which had been exclusively oral, and introduced a countrywide literacy program. His government promoted women’s rights, enabling women’s basketball to flourish; the national team played at the Pan Arab Games, and travelled to Iraq, Jordan, and Morocco.

A decade of lawlessness followed Barre’s fall, until the Islamic Courts Union, a group of Sharia courts backed by militias, assumed power. They took a harsh view of crime: thieves’ limbs were amputated, adulterers were stoned, and murderers were executed. Sports were declared satanic acts, and Somalis caught watching games on television were arrested; girls couldn’t go to stadiums to watch basketball, handball, or track and field, let alone compete in them. But, as the country reacted to the uncertainty with increasing conservatism, the Sharia courts had popular support. After a U.S.-backed Ethiopian invasion disbanded them, in 2006, a faction of their militias called al-Shabaab, or “the Youth,” rose up in response. It was even more extreme than the courts: when its members caught Somalis involved in sports, they sometimes killed them.

For five years, al-Shabaab fought bloody skirmishes for control of Mogadishu and the surrounding regions. Soldiers from the African Union, a continental organization, battled against them, with help from Somali clan militias. The United States, eager to fight terror but reluctant to send in its own troops, provided aid to the A.U. soldiers’ home countries and often ignored their human-rights abuses. Finally, in 2011, the coalition took back control of Mogadishu.

But the militants just went underground, vying with government forces neighborhood by neighborhood. (The U.S. has also conducted a clandestine campaign through Special Forces and private contractors.) Somalis still endured terror attacks near their homes and at their weddings and funerals. Government officials allegedly paid off clan militias and al-Shabaab leaders to keep their positions, and to stay alive. Drone strikes and indiscriminate neighborhood raids left young people distrustful of the government. The Islamic State has attempted to gain influence, with insurgents trying to establish outposts on the coast.