McKellen said in a blog post Thatcher was the moving force behind Section 28, a 1988 ban on schools and local authorities promoting positive views of gays, the Daily Mirror reported.
"Lest we forget, this nasty, brutish and short measure of the third Thatcher administration, was designed to slander homosexuality, by prohibiting state schools from discussing positively gay people and our 'pretended family relations,'" he said.
McKellen, who was knighted in 1991 for his contribution to theater, went public about his sexual orientation in 1988. He has been an active campaigner for gay rights ever since.
Section 28 was repealed under the Labor government. McKellen said Thatcher's last political action was voting against the repeal as a member of the House of Lords.
"She dies too early to oppose Parliament's inevitable acceptance of same-gender marriage," McKellen said.
Thatcher's funeral is to be held Wednesday in London.
Prime Minister David Cameron, an advocate of allowing homosexuals to marry, apologized as Conservative Party leader in 2009 for Section 28.
McKellen, 73, has had a notable career on stage and in movies and television. He is probably best known for playing Gandalf in the "Lord of the Rings" trilogy and now in "The Hobbit."
Notable deaths of 2014 [PHOTOS]