The buyer, who wished to remain anonymous, saw the sale advertised on the Internet and decided that the letter would make the perfect gift for his girlfriend's cake-baking mother.
The letter was discovered recently in a cupboard 104 years after Shaw wrote to Laura Ormiston Chant, a social reformer and campaigner against prostitution.
The two struck up a correspondence after he criticised her revelation that prostitutes were soliciting at a theatre in Leicester Square, London, which had prompted its closure.
In his letter of 17 November 1894 Shaw expressed sympathy for prostitutes, saying that he respected their trade "as I am bound to respect that lower depth of prostitution by which I have for so many years earned my own living: to wit, journalism".
He said that he would support a prostitutes' trade union and spoke of his high regard for sexual intercourse, condemning Victorian notions of purity and respectability.
"It is because you have idealised a certain line of conduct and branded every departure from it as impurity that the woman in the street must submit to be kicked and cuffed by the policeman," he said.
Revealing that his first affair had turned him into a "dangerous libertine", Shaw said: "I value the physical sensation of sexual intercourse about as highly as I value a piece of plum cake."
The letter was discovered at the family home of a descendant of Mrs Ormiston Chant. She had become a campaigner for social reform that eventually led to the first Children's Act after she realised that as a woman she had no legal rights over her children.
The selling price was originally estimated at pounds 800 to pounds 900 and later increased to pounds 2,000. A spokeswoman for the auctioneers, Bonham's, in London, said that the "quite unexpected" price of pounds 18,000 was the result of fierce bidding between two potential buyers.
The loser in the bidding war, who also wished to remain anonymous, last month purchased a miniature of Mrs Ormiston Chant and other papers found alongside the letter from Shaw.