MacGill hit the winning runs off fast bowler Joe Dawes to secure NSW their second title in three seasons after it appeared Queensland would steal it from them after being bundled out for 102 in their first innings.
NSW were cruising at 158 for four late in the final session on the third day of the scheduled five-day final before Dawes and Andy Bichel inspired an unlikely comeback that brought Queensland roaring back into the match.
The duo took 5-3 in the space of 18 balls to send NSW crashing to 161 for nine before MacGill combined with fast bowler and man-of-the-final Nathan Bracken for a match-winning 22-run final wicket stand.
It took NSW past the target of 183 runs with a wicket to spare after Queensland, inspired by former Test batsman Martin Love's 116, were dismissed earlier in the day for 268.
A dropped catch by wicketkeeper Wade Seccombe proved the difference in the end with Seccombe grassing a diving chance from Bracken with NSW still requiring two runs for victory.
Bracken and MacGill both finished unbeaten on 11 while Dawes (3-30) and Bichel (3-48) finished with three wickets apiece.