In a bruising contest at Brisbane's Suncorp Stadium, the Blues took an 8-0 lead into half-time after Josh Morris' 20th minute try.
A relentless second-half performance from Queensland saw them turn the match around, though.
Corey Oates got their first score of the match in the corner in the 53rd minute before Gagai's scintillating double put the Maroons 18-8 ahead with nine minutes to go.
It was a tense finish in Brisbane after Jake Trbojevic burst through the hosts' defence to score under the posts four minutes from time.
But Queensland held on, and they will now head to Perth on June 23 for Game 2 knowing another victory will seal the series.
New South Wales looked the sharper side in the breathless opening exchanges.
James Tedesco was almost put through by a lovely Nathan Cleary kick in the eighth minute, and the Blues went 2-0 ahead when the halfback converted a penalty four minutes later.
It was a Queensland player who was first over the line, though, when Oates looked to have converted a brilliant finish in the corner in the 19th minute.
But it was ruled out after consultation with the video referee:
A minute later, Morris powered over for a Blues try after Tedesco drew his man brilliantly, and this time there was nothing wrong with the finish.
Cleary converted to put the visitors 8-0 ahead, but that was as good as it got for New South Wales.
They made it to the break with their eight-point lead intact, but Queensland were in the ascendancy for much of the second 40 minutes.
And they made their dominance count as Oates produced another leaping finish into the corner, this time perfectly legally:
Kalyn Ponga then tied the scores up with a penalty after Latrell Mitchell was sent to the sin bin for preventing a potential Matt Gillett try with an illegal tackle.
With 13 minutes to play, the Blues finally had some possession near the Queensland line and looked as though they might just sneak a try.
However, Jack Wighton attempted an unnecessary offload near the corner, which Gagai intercepted and ran the length of the pitch to put Queensland ahead for the first time in the match:
The 28-year-old then went over in the corner four minutes later after Ponga's brilliant flat miss-pass took three Blues defenders out the game.
There was one more twist in the tale when Trbojevic smashed through some tired Maroons defenders to give the Blues a glimpse of their own comeback.
But it was not to be as Queensland cooly defended their way to victory.