The Commonweal School in Old Town will receive the instrument after beating competition from almost 150 entries, to win a public vote on the musician's website.
Pupils and staff made a video and sung the song which contains the lyric "Come on Jamie, give us your old piano".
Cullum said he was "thrilled" it had gone to the school.
The Yamaha piano has been used by the singer-songwriter for the past 10 years.
He said: "I have written songs on it. I have recorded albums with it. I have toured the world with it.
"It may have fallen in the mud at Glastonbury, it may have been used as a drinks table on numerous occasions, but it has also been on stage at the Royal Albert Hall and was the piano I wrote Gran Torino on.
"I am thrilled to be able to give it to a worthy home."
He said people "would think the competition had been fixed" because of his links to Wiltshire where he grew up, "but it came down to a public vote".
"I watched it [Commonweal School's video] and I was singing the song straight after. It was so much fun to watch and listen to.
"It's going to a good home that will benefit the community. It will really inspire more people to play."
The song was written by the school's music technician, Nick Weaver.
Head teacher Keith Defter said it was a "great Christmas present" for the school and the piano would take "pride of place" in the new sixth form at the performing arts academy.
A school in Swindon has won jazz musician Jamie Cullum's grand piano after writing a song about it.