After two penalties for each side, Gagai ran 80 metres for a try put Queensland 10-4 ahead at half-time.
Gagai touched down again early in the second half, before Tyson Frizell went over to give the away side hope.
But tries from Gagai and Conor Oates either side of James Maloney's score for Blues secured the hosts' victory.
Gagai's hat-trick was the first in an Origin game since Matt King scored three tries for New South Wales in the deciding game of the 2005 series.
However, he was almost denied his opening try as he was brought down five metres short of the line by Frizell, but the Newcastle Knights winger's momentum carried him over for the score.
The 25-year-old's second try was equally impressive, as he reached back to claw in a high one-handed catch and slide over in the corner.
Frizell, who became the first Wales international to feature in the State of Origin series, powered over from close range shortly after, but Gagai touched down Johnathan Thurston's grubber kick to give Queensland a lead that proved insurmountable.
Queensland: Boyd; Oates, Inglis, O'Neill, Gagai; Thurston, Cronk; Scott, Smith, McGuire, Gillett, Thaiday, Parker.
Replacements: Morgan, Lillyman, Guerra, Papalii.
New South Wales: Moylan; Ferguson, Jennings, Walker, Mansour; Maloney, Reynolds; Woods, Farah, Tamou, Frizell, Jackson, Gallen.
Replacements: Bird, Klemmer, Fifita, Bird.
Referee: Gerard Sutton
Dane Gagai's hat-trick helped Queensland beat New South Wales 26-16 to win their 10th State of Origin title in 11 years with a game to spare.