The Kenyan writer Binyavanga Wainaina in 2014. (Simon Maina/AFP/Getty Images)

Binyavanga Wainaina, a prizewinning Kenyan writer whose humorous, incisive books and essays explored themes of postcolonialism, gender and sexual identity, including his own decision to come out as a gay man in a country that long demonized homosexuality, died May 21 in Nairobi. He was 48.

Tom Maliti, the chairman of Mr. Wainaina’s literary organization, the Kwani Trust, confirmed the death to the Associated Press but did not give a precise cause. Kenya’s Daily Nation newspaper reported that Mr. Wainaina had died at a hospital after a stroke, one of several he had suffered since announcing in 2016 that he was living with HIV.

Easily recognizable by his short-cropped, rainbow-dyed hair, Mr. Wainaina was considered one of the finest African writers of his generation and a pivotal figure in Kenya’s modern literary history.

He received the 2002 Caine Prize for African Writing for his short story “Discovering Home,” a semiautobiographical tale of a young man returning to Kenya from South Africa. The next year, he founded the English-language literary magazine Kwani? (Swahili for So?), which spurred a wave of artistic creativity just as Kenya’s autocratic president, Daniel arap Moi, left office after 24 years in power.

“Binyavanga was unbound in his imagining — reminding us with art and characteristic playfulness what English can look like when it’s an African language,” Ellah Wakatama Allfrey, a Zimbabwe-born editor and literary critic, said in a tribute after Mr. Wainaina’s death.

As an editor and writer for publications in Africa and abroad, including Vanity Fair and the New York Times, Mr. Wainaina (pronounced why-NYE-na) spent much of his career working to dismantle stereotypes against gay Africans and the continent as a whole. He acquired international renown with his 2005 essay “How to Write About Africa,” a satirical response to more than a century of overgeneralized, condescending works about the “dark continent.”


Mr. Wainaina in 2014, after giving a television interview in Nairobi. (Ben Curtis/AP)

“Always use the word ‘Africa’ or ‘Darkness’ or ‘Safari’ in your title,” he began, before advising Western writers to “treat Africa as if it were one country,” “make sure you show how Africans have music and rhythm deep in their souls” and avoid mentioning “school-going children who are not suffering from yaws or Ebola fever or female genital mutilation.”

“Africa is the only continent you can love — take advantage of this,” he added. “If you are a man, thrust yourself into her warm virgin forests. If you are a woman, treat Africa as a man who wears a bush jacket and disappears off into the sunset. Africa is to be pitied, worshiped or dominated. Whichever angle you take, be sure to leave the strong impression that without your intervention and your important book, Africa is doomed.”

The essay was originally published in the British literary magazine Granta, which said that Mr. Wainaina’s article was one of its most popular pieces. “As a student, he sent the magazine a strongly worded letter condemning our 1994 Africa issue,” Granta tweeted Wednesday. “His ironic critique was so incisive and true that we published it.”

Mr. Wainaina drew glowing reviews for his 2011 memoir, “One Day I Will Write About This Place,” and three years later released what he described as “a lost chapter” from the book, “I Am a Homosexual, Mum.”

With its release online, the essay became a “gay bombshell” in Kenya, the Daily Nation wrote, and made Mr. Wainaina one of the most prominent openly gay men in Africa.

The story imagined his coming out to his mother on her deathbed — because of visa issues, he was unable to fly from South Africa to reach her in time — and his decades-long struggle to embrace his sexuality. He had known he was gay since he was 5, he said, but did not act on his feelings until five years after his mother’s death, when he received “a massage and some brief, paid-for love” in London.

“I cannot say the word gay until I am 39, four years after that brief massage encounter,” he wrote.

Mr. Wainaina said the article was inspired in part by increasing penalties against gays in Africa. Homosexual activity remains outlawed in Kenya, and the country’s High Court is expected to rule on the law’s constitutionality on Friday.

Three months after he published the essay, Mr. Wainaina was named to Time magazine’s list of “The 100 Most Influential People.”

“He felt an obligation to chip away at the shame” surrounding homosexuality, Ni­ger­ian author Chimamanda Ngozi Adichie wrote in Time. “By publicly and courageously declaring that he is a gay African, Binyavanga has demystified and humanized homosexuality and begun a necessary conversation that can no longer be about the ‘faceless other.’ ”

Kenneth Binyavanga Wainaina was born in Nakuru, in Kenya’s Great Rift Valley, on Jan. 18, 1971. His father was the managing director of an agricultural company, and his mother was a Ugandan-born hair salon owner.

By 11, Mr. Wainaina recalled in his memoir, he found himself engrossed in storybooks. “If words, in English, arranged on the page have the power to control my body in this world,” he wrote, “this sound and language can close its folds, like a fan, and I will slide into its world, where things are arranged differently.”

While in school, Mr. Wainaina preferred writing plays and novels over studying. He attended the University of Transkei in South Africa but dropped out and moved into a “one-room outhouse” to devote his life to reading.

He came to support himself through a catering and food consultancy business in Cape Town, where he developed a collection of more than 13,000 African recipes, worked as a freelance food and travel journalist, and began writing short stories. (He later received a master’s degree in creative writing from the University of East Anglia in England.)

By 2001, when he was back in Kenya, he was urging almost everyone he knew to “write, write, write” — developing a roster of photographers, poets and short-story writers who ultimately contributed to Kwani?, considered the country’s first literary journal.

“He told us that in the new Kenya, you can talk about real issues,” writer Alvas Onguru told The Washington Post in 2003. “You can talk about race and express yourself politically. So many friends and friends of friends who dreamed of being writers came out of the woodwork.”

“Since colonialism, we have been told how to think,” Mr. Wainaina told The Post. “I think most people are thrilled that those days are gone. It’s time for Kenyans to bring out their work and define themselves.”

Last year, he announced that he was engaged to his partner, a Ni­ger­ian whom he did not name publicly, saying they planned to marry and live in South Africa. A complete list of survivors was not immediately available.

Mr. Wainaina served as the director of the Chinua Achebe Center for African Writers and Artists, based at Bard College in Annandale-on-Hudson, N.Y. But for all his lectureships, speaking appearances and magazine honors, he resisted being viewed as a world-changing activist — notably when he declined the World Economic Forum’s 2007 “Young Global Leader” award.

“The problem here is that I am a writer,” he wrote in a letter to the organization. “And although, like many, I go to sleep at night fantasizing about fame, fortune and credibility, the thing that is most valuable in my trade is to try, all the time, to keep myself loose, independent and creative. . . . It would be an act of great fraudulence for me to accept the trite idea that I am ‘going to significantly impact world affairs.’ ”