Cosby was performing in Canada after a series of cancellations that followed sexual assault claims from more than 15 women.
Some of the women have accused Cosby of drugging them by slipping something in their drinks before he assaulted them.
When Cosby spotted a woman getting up from one of the front rows, he asked her where she was going. When she said she was going to get a drink, the comedian joked: “You have to be careful about drinking around me.”
The remark was met with loud applause.
When a few minutes later a heckler yelled at Cosby that he was a “rapist”, the crowd booed the man, who was eventually removed from the theatre. In a statement released after the show in London, Ontario, Cosby said: “One outburst but over 2,600 loyal, patient and courageous fans enjoyed the most wonderful medicine that exist for human-kind. Laughter.”
The 77-year-old comedian, who starred as Dr Cliff Huxtable on The Cosby Show from 1984 to 1992, has never been charged in connection with any of the sexual assault allegations.
His lawyers have dismissed the claims.
A 2005 lawsuit by a Pennsylvania woman was settled before it went to trial, and he is being sued by a woman who claims he molested her in 1974 and by three other women who allege they were defamed by the comedian when his representatives denied some of the allegations.