Hibs had an unfamiliar look about them for this trip to face League One opposition but they would have been hoping for a more comfortable night's work in Angus.
Without a full team due to a mixture of international duty and injury, Jack Ross was forced to cobble together a team with a mixture of youngsters, fringe players and old stalwarts.
And it was Gray, reduced to a bit-part this season, who won it for them in the 87th minute.
It was Jamie Gullan who was on the end of the Easter Road side's only real first-half opportunity as the Premiership side struggled against their determined hosts.
Stevie Mallan found space on the right side of the box but Forfar defender Ross Meechan was brave with a block as Gullan pulled the trigger 12 yards out.
Unfortunately for the home side, the opening period was most notable for a serious injury picked up by defender Darren Whyte, who required five minutes of treatment on the pitch before being carried off on a stretcher.
Ross brought on Martin Boyle and Kevin Nisbet after an hour and the latter got his head to a Gullan cross but the Premiership's top scorer saw his effort crash back off the junction of the post and crossbar.
The tie became stretched late on as both sides pressed for a winner and Hibs finally got the goal they needed.
Mallan swung in a free-kick from the right and Gray got his head on the delivery to clinch a third successive cup victory for the capital side.