After years of public speculation, Kevin Spacey is out of the closet.

The actor officially came out as gay after he was accused by actor Anthony Rapp of making a "sexual advance" towards him when Rapp was only 14 years of age.

The 58-year-old issued a statement on Twitter on Sunday night, saying that he has had "romantic encounters with men throughout [his] life," and has chosen now to "live as a gay man."

He added that he has had relationships with both men and women.

In his statement, Spacey said that he was "beyond horrified" to hear Rapp's allegations of sexual misconduct, which appeared in a Buzzfeed story published earlier on Sunday.

The House of Cards star said that he did not remember the incident, but if it did happen, he "owes [Rapp] the sincerest apology for what would have been deeply inappropriate drunken behaviour."

He also added it was Rapp's story that had "encouraged [him] to address other things about [his] life."

However, many on social media were unimpressed by Spacey's coming out, with some saying he was using it to divert attention.

I have absolutely no respect for Kevin Spacey. Trying to cover up Anthony's story by coming out? You're trash. — Lauren: Ragnarok (@bionicblanchett) October 30, 2017

Feels kinda gross that you’re turning a story that should be about the victim (s)...into a story about you? Congrats on coming out, I guess? — Jordan (@jordansdiamonds) October 30, 2017

"Kevin Spacey is accused of making inappropriate advances towards a 14 year old male."

Spacey: I'm gay. pic.twitter.com/yNfzE9jg43 — W👁ke (@Natural_OneDurr) October 30, 2017

Kevin Spacey : How do I apologize and get my career back on track



Lawyer : Use the gay card



Kevin Spacey : BINGO — Magnus Lewis (@magnuslewis263) October 30, 2017

Well here it goes, as a gay man I condemn the actions of Kevin Spacey and I do not accept him as a part of this community. — The Original Iramako (@WheresChungy) October 30, 2017

When Kevin Spacey tries to turn child molestation allegations into a heartwarming coming out story. Oh, Hollywood. https://t.co/M91QFQzQIH — Alana Mastrangelo (@ARmastrangelo) October 30, 2017

kevin spacey trying to use coming out of the closet to distract from anthony rapp pic.twitter.com/yfKXNKDbzk — no dana, only zuul (@DanaSchwartzzz) October 30, 2017

That Kevin Spacey statement. Nope. Absolutely not. Nope. — billy eichner (@billyeichner) October 30, 2017

Rapp's allegations date back to 1986, when he was a 14-year-old child actor who had met a then 26-year-old Spacey.

Spacey had "invited Rapp over to his apartment for a party, and, at the end of the night, picked Rapp up, placed him on his bed, and climbed on top of him, making a sexual advance," Rapp, now 46, told Buzzfeed.

“He picked me up like a groom picks up the bride over the threshold," Rapp was quoted as saying.

"But I don't, like, squirm away initially, because I'm like, 'What's going on?' And then he lays down on top of me. He was trying to seduce me."

Rapp added that he managed to break free, and eventually fled the apartment.

According to Rapp, it was the recent accusations of sexual assault and harassment against Harvey Weinstein that had prompted him to speak out against Spacey.