The Red Devils made life difficult for themselves with Mame Biram Diouf twice seeing efforts miraculously saved off the line deep into injury time, but got the result.
Mata's second-half free kick evaded everybody and flew into the corner to help the host earn the spoils after Steven N'Zonzi had canceled out Marouane Fellaini's header at Old Trafford.
United headed into the game brimming with confidence having risen to fourth in the table, despite a sluggish start to life under Louis van Gaal. And some fine early play was rewarded when Fellaini headed home a first-half opener from Ander Herrera's cross.
Stoke responded well and found a way back into the game thanks to a stunning strike from Steven N'Zonzi six minutes before halftime.
However, United regrouped upon the restart and grabbed a deserved three points thanks to Mata's intervention - albeit after surviving some scares as Mame Biram Diouf twice almost thwarted his former club.
The host seemed determined to establish a passing rhythm in the early exchanges, knocking the ball around with confidence, though a staunch Stoke backline was giving nothing away.
A golden opportunity went begging in the 16th minute as Herrera, selected as one of two injury-enforced changes because of problems sustained by Angel di Maria and Wayne Rooney against Hull City on Saturday, fluffed his lines.
Robin van Persie was the architect, intercepting Asmir Begovic's ill-judged pass and squaring to the Spaniard - who somehow side-footed over.
Yet Herrera helped atone for his error as United took the lead, sending a superb cross to the back post for Fellaini to power a header past Begovic.
United's combination of crisp passing and high-intensity pressing continued to cause problems for the visitor, but it found an equalizer against the run of play.
Fellaini coughed up possession in midfield before complaining of apparent neck pains as Bojan Krkic surged clear and N'Zonzi rocketed home from the edge of the area after the Spaniard's progress was halted.
Mark Hughes' men were again proving a tough nut to crack after the interval, but a deserved United second came when Mata's delivery missed the head of Marcos Rojo, who claimed the goal, on its way to the net.
Bojan curled a free kick wide of David de Gea's post before James Wilson - handed a first start of the campaign - curled wide having powered into the box in between two Stoke defenders.
United nearly was made to rue that miss as Stoke spurned two glorious opportunities to level.
De Gea kept out the first one, showing stunning reactions to away Diouf's far-post header. And Ashley Young denied the Senegal striker moments later, blocking his effort on the line after De Gea had saved Marko Arnautovic's strike from point-blank range to preserve three points which only strengthen United's charge into Champions League contention.