West Yorkshire Fire Service said half of Freeston Academy in Normanton, near Wakefield was ablaze at one point, leaving the building badly damaged.
More than 50 firefighters attended after the alarm was raised at 09:10 BST. The blaze was brought under control by about 12:00.
The fire service said there were no injuries and students were unaffected.
Local residents were advised to keep windows closed and stay inside at the height of the fire.
Ian Bitcon, area manager for the fire service, said the blaze was in the roof of the school which was "difficult to deal with due to access".
He said: "We've been very fortunate in that the school's unoccupied and there's been a very good water supply.
"We appear to pretty much have it cracked now."
A caller to Radio Leeds said: "I was on my way home when I saw this massive smoke and flames.
"They turned us all away and stopped us all going up the street.
"There's loads of kids here waiting for their GCSE results and they're all coming away in tears."
Students at the school were later directed to the sports hall to collect their exam results.
A woman whose daughter had been to collect her exam results at the school said: "It's been a crazy day".
She told BBC Radio Leeds: "It's been an emotional rollercoaster. First, getting up and waiting to come in and pick up the results.
"But then to hear the school was on fire. It's just been an utter drama."
In a statement, the school said: "Our main priority was the safety of our staff, students and contractors working on site, and to ensure that our year 11 students were able to collect their GCSE results.
"Following advice from the fire service, all students were able to collect their GCSE results from outside the sports hall.
"All staff on the site were accounted for and no one was hurt in the fire."

It was announced on the 70th anniversary of D-Day that the Legion d'honneur would be awarded to all veterans who took part in the invasion.
A deterioration in the health of Howard Francis, 92, prompted his family to chase his up.
He was presented with his medal in Glangwili Hospital, Carmarthen, on Monday.
Fighting for the Worcestershire Regiment, Mr Francis was shot in the shoulder near Rouen on 27 August 1944.
He received a letter which said he would be awarded the Legion d'honneur, but there was a delay due to a backlog in applications.
After he was taken ill two weeks ago, Mr Francis's family was helped by Links, a Llanelli-based charity helping ex-service personnel.
Links contacted Carmarthen East and Dinefwr MP Jonathan Edwards, who made urgent representations to Defence Secretary Michael Fallon and the French Ambassador Sylvie Bermann.
Within hours, the French embassy confirmed the medal would be fast-tracked.
Susie Hamill, manager at Links, said it had been a "quick turnaround."
"The French have been really supportive and it shows the respect they have for someone like Mr Francis and the service he gave to their country."
Mr Edwards said it was an "absolute honour" to present the medal to Mr Francis.
The medal cannot be awarded posthumously and Michael Francis, Mr Francis's eldest son, said it meant the world to his family to be given the honour.
"We're over the moon. We're so proud of him. It's hard to put into words, but I'm so happy he's got it."
A large fire broke out a school as students gathered to collect their GCSE results.
[NEXT_CONCEPT]
A Carmarthenshire D-Day veteran has been presented with France's highest military honour at his hospital bed.