Out actor Sir Ian McKellen had a hand in lowering the age of consent for gay men in Britain from 21 to 18.

The 79-year-old McKellen, who first spoke publicly about his sexuality during an interview with the BBC in 1988, is best known for playing Gandalf in the The Lord of the Rings and The Hobbit trilogies and Magneto in the X-Men films.

McKellen met at Number 10 Downing Street with then-Prime Minister John Major in 1991 to discuss gay rights.

Newly-released government files from the National Archives outline the meeting.

“If two men merely showed affection for one another publicly, they could be charged under the gross indecency laws or for a breach of the peace,” McKellen reportedly told Major.

A note from the government called McKellen's reading of the law “extreme” but acknowledged that police had used the law as “an excuse for harassment” against gay men.

“It's been encouraging to note the overwhelmingly positive response throughout the media,” McKellen wrote in a letter to Major. “There seems to be a general acceptance that the concerns of lesbians and gay men should now be firmly on the political agenda.”

Major agreed in a response, but added: “I am afraid that my postbag has contained more critical than sympathetic letters.”

The age of consent among gay men was lowered from 21 to 18 in 1994.

In a 2017 speech, Major said: “Two years later, with my encouragement, Parliament voted to lower the age of consent to eighteen – not quite the sixteen that the now Sir Ian McKellen had advocated, but a lowering nonetheless.”

The age of consent for gay men was lowered to 16 in 2000.