She made her revelation to a packed house in New York's Carnegie Hall on Friday, as part of her US book tour.
She took audience questions and was asked if Dumbledore found "true love".
"Dumbledore is gay," she said, adding he was smitten with rival Gellert Grindelwald, who he beat in a battle between good and bad wizards long ago.
The audience gasped, then applauded. "I would have told you earlier if I knew it would make you so happy," she said.
"Falling in love can blind us to an extent," she added, saying Dumbledore was "horribly, terribly let down" and his love for Grindelwald was his "great tragedy".
"Oh, my god," Rowling, 42, concluded with a laugh, "the fan fiction".
Rowling said her books are a "prolonged argument for tolerance"
Fan sites have long speculated on Dumbledore's sexuality as he was known for having a mysterious, troubled past.
Rowling told the audience that while working on the planned sixth Potter film, Harry Potter and the Half-Blood Prince, she saw the script carried a reference to a girl who was once of interest to Dumbledore.
She said she ensured director David Yates was made aware of the truth about her character.
Gay rights campaigner Peter Tatchell welcomed the news about Dumbledore and said: "It's good that children's literature includes the reality of gay people, since we exist in every society.
"But I am disappointed that she did not make Dumbledore's sexuality explicit in the Harry Potter book. Making it obvious would have sent a much more powerful message of understanding and acceptance."
And a spokesman for gay rights group Stonewall added: "It's great that JK has said this. It shows that there's no limit to what gay and lesbian people can do, even being a wizard headmaster."
Daniel Radcliffe plays Harry Potter in the films
Rowling also did a brief reading from the seventh book in her best-selling series, Harry Potter and the Deathly Hallows, as part of her Open Book Tour of the US - her first there for seven years.
She said she regarded her novels as a "prolonged argument for tolerance" and urged her fans to "question authority".
But she added that not everyone likes her work. Christian groups have alleged the books promote witchcraft. The author said her revelation about Dumbledore would give them one more reason.
The seventh Potter book broke sales records on both sides of the Atlantic when it was published in July, selling 11 million copies in 24 hours.
The fifth film adaptation of the series, Harry Potter and the Order of the Phoenix was released this summer. Harry Potter and the Half-Blood Prince is due for release late next year.
E-mail this to a friend Printable version Bookmark with:
Media caption BBC producer Elizabeth Needham-Bennett is the first to tell Kazuo Ishiguro he's won. He said he hoped the Nobel Prize would be a force for good.
Get news from the BBC in your inbox, each weekday morning
Viewers loved it , tweeting their approval with messages like, “Watching Huw Edwards do nothing on BBC news is kinda absorbing, like a lava lamp.” And love it they should. Watching TV personalities when they don’t think they’re on the air is always fascinating. See it in full below.