Ian McKellen — aka Gandalf in “The Lord of the Rings” — almost played another famed, fictional wizard as well.

McKellen was evidently approached to take over as Albus Dumbledore in “Harry Potter” when original star Richard Harris died in 2002. Harris portrayed the Headmaster of Hogwarts in the first two “Potter” pics — “Sorcerer’s Stone” and “Chamber of Secrets.”

During a recent appearance on BBC’s “HARDtalk,” interviewer Stephen Sackur brought up McKellen’s critics, recalling a remark Harris made about McKellen and fellow actors Derek Jacobi and Kenneth Branagh. Harris had said, “these guys [are] technically brilliant, but passionless.”

“Yeah,” responded McKellen. “Nonsense.”

McKellen then revealed that he received a phone call years ago about a “Harry Potter” role.

“When they called me up and said would I be interested in being in the ‘Harry Potter’ films, they didn’t say in what part,” McKellen said. “I worked out what they were thinking, and I couldn’t … I couldn’t take over the part from an actor who I’d known didn’t approve of me.”

“You mean you could’ve been Dumbledore?” Sackur asked.

“Well, sometimes, when I see the posters of Mike Gambon, the actor who gloriously plays Dumbledore, I think sometimes it is me,” McKellen replied with a laugh.

Gambon ultimately portrayed Dumbledore in the next six “Harry Potter” movies.