Koko, the gorilla whose apparent aptitude for sign language endeared her to fans around the world, died in her sleep on Tuesday morning in California, according to the Gorilla Foundation, which oversaw her care. She was 46.

Koko became an instant celebrity in her youth thanks to an early facility with American Sign Language. That fame was bolstered over the years as Koko, a western lowland gorilla, charmed entertainers like Fred Rogers and Robin Williams as well as their audiences.

“Koko touched the lives of millions as an ambassador for all gorillas and an icon for interspecies communication and empathy,” the Gorilla Foundation said in a statement. “She was beloved and will be deeply missed.”

By the age of 4, Koko had developed a vocabulary of more than 170 words and showed an ability to use language creatively, Penny Patterson, her longtime caretaker and trainer, told The New York Times in 1975.

“She occasionally makes up new words [signs] which are amazingly appropriate and she is able to string known words together in novel and meaningful constructions,” Dr. Patterson said at the time. “Koko also has a sense of humor and plays word games.”

But soon after Koko gained fame, some in the scientific community began to question the extent of her abilities, suggesting that she was responding to cues or that Dr. Patterson and others had overstated her skill, projecting what they wanted to see onto her actions. The debate has continued through the decades, but it did little to diminish interest in Koko.

Koko with Dr. Patterson. Koko was born on July 4, 1971, at the San Francisco Zoo.CreditGorilla Foundation

In public appearances, she seemed to experience emotions like happiness, frustration and heartbreak. A lifelong friend to other animals, she displayed an endearing gentleness toward cats. Her relationship with a kitten named All Ball inspired the popular children’s book “Koko’s Kitten.”

Her celebrity was also fueled in part by interactions with famous humans, like Mr. Rogers, whose show, “Mister Rogers’ Neighborhood,” featured Koko in a 1998 episode. That appearance was among the most memorable moments on the show, according to Margy Whitmer, one of its longtime producers.

Koko was quickly at ease with Mr. Rogers, playing with his sweater and telling him that she loved him.

Three years later, Koko met Robin Williams, building an instant rapport with the actor and comedian. Mr. Williams spoke fondly of the experience in interviews and even joked about their encounter in a standup routine. After he died in 2014, Koko was reportedly crestfallen.

Koko was born Hanabi-ko, Japanese for “Fireworks Child,” on July 4, 1971, at the San Francisco Zoo, according to the Gorilla Foundation. Dr. Patterson, then a doctoral student in psychology at Stanford University, began working with her the next year.

By 1979, Dr. Patterson had founded the Gorilla Foundation and moved it to the Santa Cruz Mountains.

Wild gorillas typically live for 30 or 40 years, while those cared for by humans can live into their 50s, according to the Smithsonian’s National Zoo and Conservation Biology Institute. Western lowland gorillas, like Koko, are a critically endangered species.

A version of this article appears in print on June 22, 2018, on Page A11 of the New York edition with the headline: Gorilla Who Charmed Mr. Rogers Dies at 46. Order Reprints | Today’s Paper | Subscribe