Image copyright AP Image caption Once given away, the chair was sold for over $400,000

A chair that author JK Rowling sat on while writing the first two Harry Potter books has sold at a New York auction for nearly $400,000 (£283,000).

The 1930s piece was one of four mismatched chairs that the British author picked up for free in Edinburgh, Scotland, before she rose to fame.

Ms Rowling originally auctioned the chair to benefit her charity in 2002.

She hand-painted the chair, which auctioneer James Gannon said made the piece so valuable.

It features the phrases: "O, you may not find me pretty but don't judge on what you see" and "I wrote Harry Potter while sitting on this chair".

Image copyright Reuters Image caption JK Rowling warned that the chair was hard on her back

Image copyright AP Image caption Like Harry Potter himself, the chair is marked with a lightning bolt

A letter from Ms Rowling was included with the sale.

The letter reads: "I was given four mismatched dining room chairs in 1995 and this was the comfiest one, which is why it ended up stationed permanently in front of my typewriter, supporting me while I typed out Harry Potter and the Philosopher's Stone and Harry Potter and the Chamber of Secrets. My nostalgic side is quite sad to see it go, but my back isn't."

The chair's new owner has chosen to remain anonymous.

The seller, Gerald Gray, from Salford in Greater Manchester, said the winning bid far exceeded his expectations.

"I plan to donate 10% to JK Rowling's charity, Lumos, because that's what she did in the first place," said Mr Gray.

He bought the chair in 2009 after his daughter, a Harry Potter fan, saw it on eBay.