But Danny Webber raced into the box to fire the Blades level before half-time, then netted a header from six yards after the break to make it 2-1.
QPR equalised through Kevin Gallen but Gray's penalty after a push in the box made it 3-2, before Andrew Davies' sending-off compounded Rangers' misery.
QPR boss Ian Holloway:
"I am absolutely devastated. It is not a defeat - we had it taken away from us. The referee got intimidated, I felt.
"I think I'm going to cry myself to sleep tonight because I've had my heart ripped out and stamped on.
"I feel sick to the soles of my feet over what I've seen. My boys did really well and both our goals were terrific."
Sheff Utd: Kenny, Kozluk, Morgan, Bromby, Harley, Liddell (Kabba 75), Jagielka, Montgomery, Quinn, Gray, Webber (Thirlwell 90).
Subs Not Used: David Johnson, Geary, Barnes.
Goals: Webber 43, 53, Gray 90 pen.
QPR: Royce, Bignot, Padula (Cureton 88), Shittu, Davies, Miller, Rowlands (Bailey 45), Bircham, Cook, Santos, Gallen.
Subs Not Used: Day, Baidoo, Kanyuka.
Sent Off: Davies (90).
Booked: Cook, Santos, Davies, Bignot.
Goals: Rowlands 26, Gallen 66.
Ref: L Probert (Gloucestershire).