The Aston-born musician, 73, performed on stage with his band Black Sabbath, including guitarist Tony Iommi, drummer Tommy Clufetos and bassist Adam Wakeman.
The group played their hit 1970 track “Paranoid”.
“Come on, let’s go crazy,” Osbourne told the audience, as the band played the famous chords to “Iron Man”.
Wrapping up the short performance, he added: “Thank you, good night, you are the best, God bless you all – Birmingham forever.”
Fans took to social media to share their reactions. “A Black Sabbath reunion at the Commonwealth games was the last thing I was expecting. This is awesome!” tweeted one person.
“Looked like he was having a great time,” added another.
Earlier in the ceremony, notorious fictional crime gang the Peaky Blinders took centre stage as part of a celebration of the musical heritage of the West Midlands.
The international competition came to an end on Monday night after 11 days of sporting action.
The ceremony, held at the Alexander Stadium in Birmingham, saw performances from artists including UB40, Beverley Knight, Dexys Midnight Runners, Goldie, The Selecter and Jorja Smith.
Mercury Prize-nominee Laura Mvula, 36, also gave a special performance of a newly commissioned track inspired by Nick Cave’s “Red Right Hand”, the theme song to Peaky Blinders.
The track featured a sequence from the much-anticipated theatre show Peaky Blinders: The Redemption of Thomas Shelby.
Written and adapted for the stage by the show’s creator Steven Knight, the production will receive its world premiere at Birmingham Hippodrome on 27 September as part of the Birmingham 2022 Festival.
Ahead of the event, Mvula described her performance as “sexy and dark but joyous”, and telling the PA news agency she felt “chuffed” for Birmingham.
“Generally, especially among other parts of the UK I have been to, Birmingham has tended to get a bad rep,” she said.
“It’s the second city. It’s not London. That’s all we know of it – and the accent.
“But what I love about Peaky Blinders, that I’ll be tributing in my performance tonight, is that they have made the Birmingham accent golden again.
“It’s something that I’m proud of and I embrace more. I love it now when people go, ‘Are you from Birmingham? I can hear it in your accent,’ because it’s part of my heritage.”
2022 has seen the most successful Commonwealth Games ever for the home nations, with a combined total of 275 medals, including 85 golds.
England led the way with 57 golds, behind only Australia in the medal table, and 176 in total, while Northern Ireland set national records and Scotland and Wales also thrived.
The Duke of Wessex officially closed the ceremony, saying: “Every four years, we endeavour to come together to celebrate our Commonwealth through sport.
“Thanks to the manner, style and enthusiasm with which you have competed, officiated, supported, organised and volunteered, you have, once again, brought the spirit and values of the Commonwealth to life.
“You have inspired us and hopefully future generations. You have also demonstrated what unites us. Thank you, Birmingham.”
Additional reporting by PA