Gray’s goals ensured the Minstermen lost their second pre-season friendly in four days to Championship opposition but, as in Saturday’s 1-0 home defeat against Hull City, the Bootham Crescent club were beaten but far from overwhelmed.
Leeds United first-year professional Liam Darville, meanwhile, was given a run-out at right-back with fellow trialist David McDermott also named in the starting line up.
Teenage midfielder Mike Whitwell, released by Leeds at the end of last season, also came on as a first-half substitute for Chris Carruthers.
Between the stricks, trialist ’keepers Steven Drench and David Knight were also handed a half apiece.
The visitors brought an impressive following of fans to Bootham Crescent and it was the Oakwell men who created the first chance of the evening.
Purposeful left-winger Martin Devaney cut in from the flank and fired across the face of Drench’s goal on 13 minutes.
Moments later, the Tykes lost centre-back Stephen Foster for ten minutes as he required stitches to a cut eye following his aerial challenge with City striker Michael Rankine.
In his absence, Rankine drove wide of the near post with a low 20-yard effort and George Purcell forced the first save of the night on 23 minutes when Luke Steele dived to his left to keep out the former Braintree striker’s edge-of-the-box strike.
After Foster’s return, referee Mark Heywood puzzlingly pulled back play to award City a free-kick in their own half when Rankine was charging on to a Purcell through ball.
Heywood also appeared to overlook certain fouls while City midfielder Jonathan Smith would have been booked during a league match for his late challenge on Barnsley’s Jim O’Brien.
The Minstermen’s biggest goal threat continued to come from Purcell, whose 25-yard shot just past the half-hour skidded quickly off the surface with Steele requiring two attempts to safely smother the ball.
It was Mark Robins’ men who forged ahead, however, when Goran Lovre’s lay-off found Gray and he spun his marker Djoumin Sangare before firing clinically into Drench’s top right-hand corner from 15 yards.
City’s injury-plagued squad suffered another blow on 43 minutes when Chris Carruthers limped out of the action.
But his replacement Whitwell almost got on the scoresheet within seconds, forcing Steele into an excellent reflex save from his downward header following a right-wing cross from McDermott.
Foyle made a further five substitutions at the break, while Robins unusually decided to retain the same starting XI for the second half.
The visitors made an encouraging restart with a swift attack seeing Knight smother at the feet of Gray following Devaney’s cross.
Another blistering burst by Devaney on the hour teed up an opportunity for Iain Hume that he sidefooted wastefully over.
At the other end, Neil Barrett shot wide after good work by McDermott and Richard Brodie, who also barged his way through the Barnsley defence before Steele raced off his line to deny him. Michael Gash then had a far-post header clawed away by the Tykes’ stopper and Devaney again threatened on the counter attack but failed to capitalise on a two-on-one situation, eventually being fouled by Darville in what would normally have amounted to a red-card offence.
Gray, though, grabbed his second goal of the night on 70 minutes, rising high to head Hume’s right-wing cross in off Knight’s left-hand upright.
Star man Devaney might have added a third for the visitors but his firmly-struck volley was beaten out by Knight, who also showed admirable handling to hold on to a late Lovre rising strike.
City: Steven Drench (David Knight, 46), Liam Darville, Djoumin Sangare, Daniel Parslow (Dean Lisles, 68), James Meredith (Andy McWilliams, 68), David McDermott (Jamie Hopcutt, 74), Jonathan Smith (Levi Mackin, 46), Alex Lawless (Neil Barrett, 46), Chris Carruthers (Mike Whitwell, 43), Michael Rankine (Michael Gash, 46), George Purcell (Richard Brodie, 46).
Barnsley: Luke Steele, Bobby Hassell, Steve Foster, Jason Shackell, Jay McEverley, Martin Devaney, Nathan Doyle, Goran Lovre, Jim O’Brien, Iain Hume (Jamil Adam, 77), Andy Gray (Liam Dickinson, 77).
Referee: Mark Heywood.
Attendance: 1,393 (595).