The Tykes came into the match having suffered back-to-back losses to Cardiff and Bristol City respectively as they hovered just above the Championship relegation zone while promotion chasers Hull had not been defeated in nine games.
Barnsley turned the form book on its head though as first, Davies fired home from close range then Gray capitalised on Adriano Basso's spillage of Danny Drinkwater's fierce drive.
The Tigers had their chances in an end-to-end first half, however, most notably when Matty Fryatt saw his penalty saved by Luke Steele.
Fryatt made amends with a fine strike on the edge of the area in the 79th minute to set up a grandstand finale but Barnsley held on.
It meant that Hull suffered their first loss since August 20 but Keith Hill's men claimed a precious three points in their bid for survival.
In an open first half full of attacking intent, it was Barnsley who went the closest in the opening stages as Gray glanced a free header from Jay McEveley's cross wide of the right-hand post.
At the other end Joe Dudgeon's effort was parried into the path of Robert Koren but the midfielder's follow-up was deflected wide.
The match continued at a frenetic pace and Hull were given a marvellous opportunity to open the scoring in the 27th minute when they were awarded a penalty.
Barnsley midfielder Drinkwater was dispossessed in his own half by Corry Evans and his defence splitting pass found Robbie Brady, who was hauled down in the box by Jimmy McNulty.
However, Fryatt's low effort to the right was superbly tipped on to the post and out to safety by Steele.
Davies failed to make Nigel Pearson's men pay for their profligacy when he shot wide of the target despite going clean through on goal after latching on to Jacob Butterfield's pass.
It somehow remained honours even at half-time but it took just three minutes for the deadlock to be broken after the interval.
Jim O'Brien slotted through to Gray in acres of space in Hull's penalty area and he squared to strike partner Davies, who duly stroked high into the net.
The provider then turned goalscorer as the Tykes extended their lead in the 59th minute.
Drinkwater capitalised on hesitation from James Chester and Evans and although his rasping drive was straight at Basso, the Hull stopper spilled the ball straight into the path of a grateful Gray to tap in.
The Tykes were nearly pegged back in spectacular fashion though, with Aaron Mclean's overhead kick cannoning off the bar.
Hull were rewarded for their persistence 11 minutes from time when Fryatt lashed home on the edge of the area after being teed up by substitute Dele Adebola.
A similar strike immediately after took a deflection but this time Steele was on hand to claw away as Barnsley fought to protect their lead.
Mclean fired wide of the post, while Davies could have wrapped up the points for Barnsley but after rounding substitute goalkeeper Peter Gulacsi, his effort was cleared off the line.