Gray came off the bench to score a fortuitous winner six minutes from time after the Bees had earlier twice come from behind to record a 3-2 win which maintained their all-important position in the top six.
Clinical finishes from Rudy Gestede and Chris Taylor either side of Chris Long’s deflected effort had given Rovers a half-time lead as they looked to cut the gap on their opponents to five points.
However, after Jota had levelled early in the second half, Gray scored a goal which may have ended Blackburn’s top-six aspirations once and for all with eight games to go.
Gary Bowyer paired Jordan Rhodes and Gestede together in attack for the first time since their most recent defeat to Norwich six games ago and the decision was vindicated within five minutes.
Ben Marshall’s quick thinking caught the Bees’ defence napping from a free-kick and Gestede raced on to the ball before blasting it into the top corner for his 16th goal of the season.
Rovers were clearly buoyed by that opener and seemed intent on wrapping up the contest early as Taylor drilled a chance into the side netting after being allowed to pivot inside the area.
Brentford were offering little at the other end but Jason Steele made a wonderful save to divert Harlee Dean’s header away from under the home side’s crossbar.
Taylor came close again with a low shot straight at goalkeeper David Button but it was Alan Judge, once of Blackburn, who went closer still with a beautifully shaped free-kick which crashed off the frame of Steele’s goal.
Mark Warburton’s men did find an equaliser 44 minutes in as Everton loanee Long drove into space and found the net with a deflected effort which Matt Kilgallon’s sliding intervention took beyond Steele.
However, there was still time for Rovers to restore their lead before the break with a well-crafted move.
Corry Evans and Tom Cairney were both involved on the edge of the area and Rhodes turned the ball around the corner for the overlapping Taylor, who fired emphatically into the roof of the net in the fourth minute of first-half stoppage time.
The advantage was quickly erased again at the start of the second period as Jota brought his side level for a second time on the night.
Steele had already made a smart near-post stop to deny Stuart Dallas, but he was unable to prevent Jota rifling past him after a 60-yard unopposed run which infuriated the home support.
Ben Marshall, who had given possession away in the build up to Jota’s goal, was withdrawn for Jay Spearing and the substitute found an unmarked Rhodes in the area, but the Scotland international guided his header well wide when he probably had enough time to take a touch.
Gestede blazed a Taylor cutback over the top, however there was still disbelief from the Blackburn faithful when Bowyer replaced him with Chris Brown with 16 minutes remaining.
Yet it was another substitute who would make the telling contribution as Steele pushed Jota’s deflected effort on to Gray’s body and the ball ricocheted over the line to perhaps signal the end of Blackburn’s late play-off charge.