Three weeks later, terrorists flew two planes into the World Trade Center. Watching news clips in which Muslim fundamentalists claimed that their religion was incompatible with the West, Wilson started to believe them. She sought out critics of Islam, hoping to puncture her attraction to it; she read novels by Hanif Kureishi and Salman Rushdie. “I had high hopes that ‘The Satanic Verses’ would cure my religiosity,” she writes; it did not. For the next two years, she “went back to the regular college diet of jello shots and wine in a box.” Still, she remained unconvinced that she could live a secular life. Shortly before graduation, she took a job teaching English in Cairo, and, on the plane to Egypt, she “made peace with God. I called him Allah.”

In Cairo, she began practicing Islam openly. Through a friend, she met a religiously traditional Egyptian man who loved art and taught physics; when they got engaged, two months later, they had not yet kissed. She began to wear a hijab. She contributed to Cairo Magazine—a now-defunct publication that challenged the Mubarak regime—as well as the Times Magazine and The Atlantic. And she started writing comic books, for DC, including a one-off issue of “Aquaman,” which she puckishly set in the Sahara Desert, and a limited run of “Vixen,” a series starring a female superhero from the fictional African nation of Zambesi.

In 2009, Wilson moved back to the U.S. with her husband. She struggled to readjust—she had never lived as a Muslim in her own country. Her memoir was published the following year and then, in 2012, came her novel “Alif the Unseen,” a techno-fantasy about an Arab-Indian hacker. In a twenty-month stretch, she went on two book tours and gave birth to two daughters. Then she got a call from Stephen Wacker, a longtime Marvel editor, and Sana Amanat, at the time an assistant editor. Wacker and Amanat had decided that the new Ms. Marvel series should star a Muslim teen-ager, and that Wilson should write it. Amanat, a Pakistani-American Muslim, would be the series editor. (Amanat also edits the “Hawkeye” and “Captain Marvel” reboots, and has since become a director of content and character development at Marvel, known for her striking and unorthodox instincts.)

The idea seemed, to Wilson, shocking and wonderful; she had become resigned to compartmentalizing her faith and her interest in superheroes. She wrote her first comics shortly after the firestorm over Danish cartoons of the Prophet Muhammad, in 2005, and when, in 2010, she wrote two fill-in issues of “Superman,” a message-board community had lamented DC’s flagship falling into the hands of a Muslim. “I could see the headlines,” Wilson recalled, of her thinking about Kamala Khan: “SHARIA LAW AT MARVEL!” For a year, she and Amanat talked on the phone multiple times a week, for hours at a time, drafting different versions of Kamala. Every decision was freighted. Would she cover her hair? Could they find an artist to draw her without that cartoonishly voluptuous female-superhero chest? They knew the many lines along which the character could be criticized: traditional Muslims might want her to be more modest, and secular Muslims might want her to be less so. Some would be wary no matter what.

The conventional superhero brings peace through retributive violence; when Batman saves Gotham, much of the city is destroyed. This trope, Wilson knew, sat uneasily with certain Western ideas about Muslims. For a time, she suspected that only a tongue-in-cheek approach would work. “I had originally envisioned her power set very differently,” she said of Kamala. “Explode-y powers, an ironic type of thing.” On the day of the Boston Marathon bombing, carried out by two young men who subscribed to radical Islam, she changed her mind. “I sat down and I tried to think, What would I want to put in their hands instead of the story they’d been given? What would the world look like if they didn’t have to be the bad guys? How can I draw on the same faith tradition and arrive at the opposite place?” Twenty-four hours later, she had figured out Kamala’s backstory.

The first panel of the first issue, lushly illustrated by Adrian Alphona, is a close-up of a deli B.L.T. The sandwich is off limits for Kamala, who, like any teen-ager, is figuring out her loyalties: she doesn’t wear a hijab but she also doesn’t eat pork. She’s a Peter Parker type—anxious, clumsy, winsome. One Friday night, she’s stuck at home writing Avengers fan fiction; her father disapproves of her going to parties as much as he disapproves of her unemployed, pious brother praying all the time. When she sneaks out of the house anyway, she gets caught in a mysterious fog, which activates her shape-shifting powers and induces a psychedelic vision of the first Ms. Marvel, Carol Danvers. Soon afterward, Kamala transforms into Carol and saves a classmate from drowning. The heroics feel more natural to her than the blond hair and skimpy costume. The next time she goes off on a mission, she straps on a fanny pack over an outfit she’s made from an unworn burkini.

The first page of “Ms. Marvel, No. 1.” COURTESY MARVEL COURTESY MARVEL

In Wilson’s view, there’s a “neat ideological overlap between superhero comics and religion, in a positive sense. Both things are about voluntarily holding yourself to a superhuman ideal, doing good even when it’s not required of you.” Still, she and Amanat were intent on creating a character who would frequently fall short of the standards set for her. Wilson drew on memories of her post-Cairo readjustment period, when second-generation friends had taught her that navigating two cultures could be funny, that imperfection was fine. In one issue, Kamala argues with Sheikh Abdullah about the mosque’s side entrance for women; in another, she ruins her brother’s engagement party while trying to save the planet.

Eventually, Kamala grows into a natural shape-shifter, both in terms of her superpowers and her ability to navigate multiple worlds: an immigrant family, high school, the Marvel universe. Wilson draws out the humor in Kamala’s rapid code-switching. Though the series is warmhearted, it’s never cloying. (At a Valentine’s Day dance in Issue 12, Nakia, a hyper-woke teen, groans, “I can’t believe I let you drag me to this patriarchal capitalist display of false affection.”) A couple of years into the series, Kamala has joined the Avengers, and is an established figure in Jersey City, where evil has arrived in the form of gentrification: hipster tenants are being drawn to a high-rise condo built by the criminal organization Hydra and genetically reprogrammed through purple kombucha. In an attempt to damage her reputation, Hydra uses Ms. Marvel’s costumed visage to advertise the new development; protests calling her a sellout ensue. Meanwhile, Kamala is struggling to keep up with her teen-superhero duties. She makes golems of herself, which multiply into an enormous army of mindless, destructive Kamalas, wreaking havoc all over town.

The première of “Ms. Marvel” sold more copies digitally than it did in print—a company first. Marvel doesn’t release digital-sales numbers, but piecemeal statistics have shown female characters performing especially well in digital formats. Traditionally, comic books are purchased in single, floppy issues at dedicated brick-and-mortar shops, but these can be intimidating spaces for novices: when I walked into Forbidden Planet in Manhattan, I found myself wishing for the ability to act like I belonged. Some readers may simply opt to buy collected issues in paperbacks at regular bookstores or, increasingly, to download e-books. There are now, Wilson suggested, two audiences for comic books, and many people in the industry “are loath to recognize that these two audiences might want two very different things out of the same series. They don’t shop in the same places, they don’t socially overlap, and their tastes might not overlap.”