An exceptionally entertaining second half witnessed five goals as the Blues were twice made to retake the lead by a Potters side who gave them one of their toughest tests this season.
Gary Cahill gave Chelsea the lead when he headed in shortly before half-time, but Stoke defender Bruno Martins Indi levelled only a minute after the break when he poked in from close range.
Willian handed the Blues the advantage again only for Peter Crouch to level with a side foot effort high past Thibaut Courtois.
Stoke barely had time to celebrate, as moments after the restart Chelsea drove towards goal with Willian applying an fierce angled finish.
With five minutes remaining, the Blues all but sealed the three points when Diego Costa – who was magnificent as a target-man – shrugged off the attentions of Martins Indi to fire in the fourth.
The home side had fallen behind when Grant Leadbitter gave Boro a shock lead, drilling home a low finish from Alvaro Negredo’s knock down.
Up until then, United had bossed a match in which Pogba struck the post with an overhead kick and Martial hit the same upright with a long-range strike.
Zlatan Ibrahimovic also had a goal harshly ruled out for a high boot on ex-United goalkeeper Victor Valdes, while the Spaniard twice blocked the United striker’s shots from close range in the second half.
With time running out, Frenchman Martial poked in on 85 minutes and fellow countryman Pogba headed into the top corner a minute later.
Having been frustrated following wave after wave of attacks, it looked like United were going to be left without a point when they fell behind at home to Boro.
Jose Mourinho’s men had forced Valdes into 10 saves – which highlighted their dominance – and it looked like being a clean sheet for the keeper on his return to Old Trafford.
But United’s 65% possession was worthwhile in the end as Martial and Pogba scored within one minute and 20 seconds of each other to spark jubilant scenes from both the home players and supporters at the final whistle.
The world’s most expensive player Pogba danced in the middle of the pitch, while boss Mourinho hugged counterpart Aitor Karanka in consolation.
The Red Devils are now unbeaten in their last 10 league games – winning all five in December – and are just one point adrift of fourth-placed Arsenal.
Gray, who was playing in the sixth tier of English football with Hinckley United in 2012, netted his first after a defensive mix-up between John O’Shea and Papy Djilobodji.
The striker rounded Vito Mannone for his second before completing his treble with a low shot from Ashley Barnes’ pass.
Barnes converted a penalty to make it 4-0, before a consolation goal from Jermain Defoe after good play from Adnan Januzaj.
Leicester end poor run with a lone goal victory over West Ham
Leicester City pulled six points clear of the Premier League relegation zone as Islam Slimani’s header ended West Ham United’s three-match winning run.
Slimani had already headed against the post when he nodded home Marc Albrighton’s excellent cross.
Home keeper Kasper Schmeichel twice denied Dimitri Payet with fine saves, while Michail Antonio hammered a shot against the Leicester bar.
Schmeichel also did well to keep out Aaron Creswell’s deflected free-kick as champions Leicester ended a momentous 2016 with a first clean sheet in 12 league games.
The win lifts the Foxes one place to 15th, while West Ham’s first league defeat since 3 December means they drop from 11th to 13th.
Leicester chairman Vichai Srivaddhanaprabha rewarded the club’s older fans with a free beer before the game.
It was not to drown their sorrows despite a poor first half to the season, but to reward them for their backing during a historic year in which the 5,000-1 outsiders won the title.
And many of the ingredients that contributed to the Foxes being crowned champions were back on display in their final game of 2016.
Leicester have been accused of looking ragged and lacking in ideas lately. Against West Ham, they were hungry, determined and energetic as they tore into their opponents in the first half and gave fans hope they will not spend 2017 embroiled in a relegation fight.