The twist will force Margulies' character to examine all aspects of her life, producers said.
"She's going to miss the existence of Will," Margulies said of her character. "He was a powerful aphrodisiac in her life."
Once the episode had aired, Twitter lit up with astonished, sorrowful and even irate posts.
One viewer called for a group hug, while another issued a plea for a counselor to treat jolted fans. Yet another viewer expressed hope that, as with "Dallas" long ago in revealing Bobby Ewing's death to be only a dream, "The Good Wife" would find Gardner stepping out of his shower next week, alive and well.
Other viewers vowed never to watch the show again, as payback.
Charles said he appreciated the support of fans, but urged those who are upset to take a step back.
"I understand that there will be audience members who will be upset," Charles said. "I would just tell them that I guarantee it will continue to be an excellent show. I know I'm going to keep watching it."
His death and Charles' decision to exit the show had been well-guarded secrets. Charles, who entered the series with a four-year contract, opted not to re-up when it expired after last season, according to his publicist.
Charles' past TV work includes the ABC dramedy series "SportsNight" and a season playing a client of therapist Gabriel Byrne on the HBO drama "In Treatment."