TORONTO -- Mike O'Brien, a longtime CBC comedy writer and an actor who played a recurring character on "Corner Gas," has died of cancer. He was 51.

O'Brien mixed humour and pathos in chronicling his four-year illness on his blog The Big Diseasey and had posted a meditation about faith -- or lack thereof -- just hours before his death.

He died at his Winnipeg home on Sunday night, said his agent Lisa Marie Schwartz.

"(He) was not only an amazing actor but a great friend," Schwartz said in a statement.

"Corner Gas" executive producer Virginia Thompson said O'Brien's blog, which included satirical observations on his condition and poignant musings about his time left, is his legacy.

O'Brien's ability to find humour in even the bleakest situation was one of his defining traits, Thompson said.

"The thing about people that truly understand comedy is they have a way of twisting things so that we can see things in a different light. They see the irony of the world and they're able to deliver it to us," Thompson said in a telephone interview.

"That's exactly the guy that was on our set. That's the guy that we fell in love with."

Last November, O'Brien blended fact and humour in a mock obituary he penned for his blog.

Facts about his life, such as his childhood spent in Victoria and Inuvik and his adult years living in Regina and Winnipeg, appeared alongside a self-deprecating summary of his professional accomplishments.

"As an actor, he made you feel like he was standing right where the director told him to stand; a skill he shared with Olivier, Brando and many puppets," O'Brien wrote.

"As a radio producer, he boosted television ratings. As a comedy writer, he was tall."

In reality, O'Brien's resume was both more diverse and more celebrated. He began his career as a journalist for the Medicine Hat News and Regina Leader Post and eventually switched to acting.

He landed recurring roles on some prominent Canadian comedies and is best known for his portrayal of Wes Humboldt, the combination liquor store owner and insurance salesman on CTV's "Corner Gas."

Thompson said O'Brien quickly became a beloved member of the "Corner Gas" family, adding that cast members organized a fundraiser for him and his family when his cancer was first diagnosed in 2011.

Series star Brent Butt took to social media to express his condolences.

"Sad to say, the lovely & clever Mike O'Brien -- who, among many things, played Wes Humboldt on 'Corner Gas' -- has passed away. .CancerSucks," Butt tweeted.

O'Brien also had a recurring role on the HBO Canada comedy "Less than Kind."

But it was radio where he spent the better part of his later career, working largely as a comedy writer for the CBC.

On his blog, O'Brien penned a largely serious post on the subject of faith in the hours before he died, downplaying the role of religion in his life and expressing more confidence in his medical team.

He also referenced the wife and four-year-old son he left behind, citing optimism for their future as a key source of comfort.

"Above all, I have faith Robin will guide Will toward a fine life," he said. "That's the belief I treasure the most."

In an interview with CTV Vancouver Island, 'Corner Gas' actor Mike O'Brien spoke about making the most of the time he has left.