Clarence Williams III, who played the cool undercover cop Linc Hayes on the counterculture series “The Mod Squad” and Prince’s father in “Purple Rain,” died June 4 at his home in Los Angeles. He was 81.

The cause was colon cancer, said his manager, Allan Mindel.

Mr. Williams got his start on Broadway before starring in “The Mod Squad,” about three undercover “hippie cops” in Los Angeles. Running on ABC from 1968 to 1973, the show was among the first to examine the hippie generation — episodes dealt with issues including the Vietnam War, abortion and drug use — and one of the first to feature an interracial cast.

The show starred Peggy Lipton and Michael Cole alongside Mr. Williams, whom Bill Cosby had suggested to producer Aaron Spelling. After it went off the air, Mr. Williams appeared on Broadway in Tom Stoppard’s play “Night and Day” (1979), opposite Maggie Smith, and played the troubled father in “Purple Rain” (1984).

He appeared frequently in movies, working with director John Frankenheimer on films including “Against the Wall” (1994) and “Reindeer Games” (2000). Frankenheimer first cast him in his 1986 adaptation of Elmore Leonard’s crime novel “52 Pick-Up,” at a time when Mr. Williams was not having much luck in Hollywood and crashing on Cosby’s couch to keep a roof over his head.

“He asked me to read for the part of one of the blackmailers, but after only four lines, he told me to stop,” Mr. Williams recalled in a 1999 interview. “I thought it was all over, but he said, ‘Have your agent call me. It will be a 10-week shoot. Thank you for coming in.’ That was it.”

Mr. Williams appeared in TV crime dramas including “Miami Vice” and “Hill Street Blues” and played an FBI agent in the mystery-drama “Twin Peaks.” But he also excelled in comedies, playing a drug lord opposite Dave Chappelle in “Half Baked” (1998) and stealing scenes in Keenen Ivory Wayans’ blaxploitation parody film “I’m Gonna Git You Sucka” (1988).

His other film roles included a narcotic detective in “Deep Cover” (1992), Wesley Snipes’s drug-addicted father in “Sugar Hill” (1993) and a sinister mortician in “Tales from the Hood” (1995). He also played a devoted adjutant in “The General’s Daughter” (1999) and the mentor of a White House domestic worker in Lee Daniels’s “The Butler” (2013), one of his last movie roles.

Clarence Williams III was born in New York City on Aug. 21, 1939. His father was a musician, and Mr. Williams was raised by his paternal grandparents.

After serving as an Army paratrooper, he performed in Broadway plays such as William Hanley’s “Slow Dance on the Killing Ground” (1964), for which he received a Tony Award nomination and a Theater World Award.

His marriage to actress Gloria Foster ended in divorce. Survivors include a daughter, Jamey Phillips; and a sister.

Mr. Williams often said he didn’t mind being known for “The Mod Squad,” even though his career stretched across nearly 100 movies and television shows.

“All most people know about me is the two hours they’ve invested in a movie theater or the time spent in front of their TV,” he said in a 1999 interview. “There’s so much entertainment out there right now, it’s difficult to break through and become part of the national consciousness. It’s nice to be recognized, and I have no problem with it at all.”