Conchata Ferrell, the award-winning theater actress who became a television star as the gruff housekeeper of a toxic Malibu bachelor on the sitcom “Two and a Half Men,” died on Monday in Los Angeles. She was 77.

The death, in Sherman Oaks Hospital, was confirmed by her daughter, Samantha Anderson.

Ms. Ferrell was hospitalized in December for a kidney infection, which spread to her bloodstream. In May, a heart attack put her in intensive care for four weeks. She was then moved to long-term care, remaining on a respirator and on dialysis until her death.

When CBS was casting “Two and a Half Men,” the character Berta — who cleaned the oceanfront home of Charlie Harper (Charlie Sheen), a successful writer of jingles and children’s songs — was written as Eastern European. But Ms. Ferrell preferred to do it in her own voice. “It works better in Trailer Park,” she told the producers, who quickly agreed — and even changed their minds about having Berta disappear after two episodes.

In a role that brought her two Emmy Award nominations for best supporting actress in a comedy series, Ms. Ferrell appeared as Berta in more than 200 episodes between 2003 and 2015. (Ashton Kutcher replaced Mr. Sheen in the last four seasons.) Her Berta was a merciless, unshakable, ungrammatical old hippie with an expansive knowledge of the phone numbers of local drug dealers. She gave other characters unwelcome nicknames (Zippy for Charlie’s brother, Alan, played by Jon Cryer; Fatal Attraction for Rose, the neighborhood stalker, played by Melanie Lynskey).

She once cornered Charlie, demanding that he clarify her “place” in the household. “Wherever you want it to be,” he said.

Ms. Ferrell explained her character’s largely unspoken admiration for Charlie in a 2014 A.V. Club interview. “I liked the fact that he lived the way he lived and he said what he said and he did what he did,” she said, speaking as Berta. “I liked him because he was a classier version of me.”

Ms. Ferrell had achieved acclaim decades earlier in New York theater, appearing as the prostitute April in Lanford Wilson’s “The Hot L Baltimore” (1973), a role he wrote for her. The play won multiple awards, including an Obie for best Off Broadway play, and ran for three years.

Ms. Ferrell collected her own Off Broadway prizes, including the Drama Desk Award for best actress in a play and an Obie, for her performance as a disillusioned waterfront-bar owner in “The Sea Horse” (1973).

She received her first Emmy nomination in 1992 for a recurring role as Susan Bloom, a ruthless entertainment lawyer with more money than manners, on “L.A. Law.”

She later said the three favorite characters she had played were Berta, April and Susan Bloom. What they had in common, she said in a 2018 interview with The Huntington Quarterly, a West Virginia magazine, was “a zest for living life to the fullest in the best way available to them.”

Conchata Galen Ferrell was born on March 28, 1943, in Loudendale, W.Va., near Charleston, the state capital. Her father, Luther Ferrell, a factory worker who considered himself lucky not to be in the mines, advised his only child to find a job that she actually enjoyed. Her mother, Mescal (George) Ferrell, carried on her family’s tradition of giving girls unusual names.

The family moved to Ohio, but Conchata returned to spend two years at West Virginia University. She then worked at various jobs, including waitress, hotel desk clerk and assembly-line worker. She tried college again in the late 1960s, earning a bachelor’s degree in education from Marshall University in Huntington.

Encouraged after appearing in Marshall’s annual comedy revue, she moved to New York and became part of the Circle Repertory and Circle in the Square theater companies. Her stage debut was in Chekhov’s “The Three Sisters” — playing the maid.

Her first appearance on any screen was on the sitcom “Maude” in 1974, where she was presciently cast as a maid. Norman Lear, the creator of “Maude” and just about every other prestigious ’70s TV comedy, bought the rights to “The Hot L Baltimore” and cast Ms. Ferrell in her original stage role. The series, possibly too risqué for 1975, was one of Mr. Lear’s rare failures. (But, Ms. Ferrell recalled, “it was a good 13 weeks.”)

She notably played the judge who refused to annul Ross and Rachel’s Las Vegas marriage on “Friends” (1999). But she often went dramatic too, playing a homesteader’s wife in the 1979 movie “Heartland” and appearing on series including “Knots Landing,” “Lou Grant” and “Touched by an Angel.” In a 1986 television version (and Los Angeles stage version) of William Inge’s heart-wrenching drama “Picnic,” she played the kind widow who hires a dangerous drifter.

Ms. Ferrell also had small roles in big movies, including “Network” (1976), as a television executive appalled by Faye Dunaway’s series ideas, and “Edward Scissorhands” (1990), as a neighborhood lady in pink hair rollers. She starred as a pizzeria owner in “Mystic Pizza” (1988), with a cast that included a young Julia Roberts. The two reunited in “Erin Brockovich” (2000), with Ms. Ferrell as Albert Finney’s secretary.

Her final roles were in “Deported” (2020), a comedy about love and immigration, and “A Very Nutty Christmas” (2018), a television movie about love and holiday cookies.

Ms. Ferrell married Arnie Anderson, a film-industry sound mixer, in 1986. He and her daughter survive her, as do two stepdaughters, Lisa and Caitlin Anderson.

Like her characters, Ms. Ferrell had opinions. Discussing the French actress Simone Signoret, a leading lady who had just turned 60, in a 1981 video interview, she said: “Thank God she’s not American. They wouldn’t let her work.” Referring to Marlon Brando’s pay for “Superman” (1978), she declared: “No actor is worth $3 million, not even Marlon. It puts too many other actors out of work.”

But she was blissful about her own good fortune. “I feel like the reason I’ve survived in this business is because I love acting,” she said in the A.V. Club interview.

“I mean, I fulfilled my dad’s desire for me,” she added. “I love what I do.”