Teen drama Riverdale featured a cameo from Luke Perry’s former co-star Shannen Doherty as it bid farewell to the late actor.

Perry, who rose to fame after starring alongside Doherty in hit 90s show Beverly Hills 90210, died in March after suffering a stroke.

The 52-year-old played Fred Andrews in Riverdale and his death came in the middle of its third season, leaving three episodes left to film.

Show creator Roberto Aguirre-Sacasa said rather than hastily address the character’s exit, he wanted to take the time to give him a fitting farewell.

The season four premiere aired in the US on Wednesday, informing the audience that Fred, the father of Riverdale’s main character Archie, had died.

The emotional episode featured a funeral for the character and a cameo by Perry’s close friend Doherty.

Archie, played by KJ Apa, discovered his father was killed after stopping at the side of the road to help a stranded driver in another town.

The arrangements to return Fred’s body back to Riverdale were delayed until after July 4 celebrations, before Archie decided to retrieve it himself.

In tear-jerking scenes, Archie sifts through his father’s belongings in his truck, before a car pulls up behind him.

A mystery woman – played by Doherty – steps out and it is revealed she is the motorist Fred stopped to help. She says a prayer for Fred before leaving Archie and his friends to bring Fred back to Riverdale.

As they enter the town, its residents come out to honour Fred, holding up signs with slogans including “We will never forget you, Fred”.

At the funeral, Archie delivered a tearful eulogy to  a crowd of grieving family and friends.

“My dad was here for every high and every low. He’s the greatest man I’ve ever known. It hurts me that I never got to say goodbye,” he said.

“But his spirit and his memory lives on, in this town and in everyone he’s met. Fred Andrews will always be a part of Riverdale. I love you so much, Dad.”

The job of writing Fred’s obituary is left to Archie’s best friend, Jughead Jones, played by Cole Sprouse.

The main characters are seen reading the obituary while Sprouse reads it out via a voice-over.

It ends with him saying: “Fred left Riverdale better than when he found it. That’s his legacy.”

The episode finished with the cast gathered in Archie’s back garden, lighting fireworks for July 4.

After the episode aired, Riverdale star Lili Reinhart paid tribute to Perry. She praised Apa’s performance and said Fred will  “always be a part of” the show.

She added: “We love and honor you every single day, Luke.”