Both sides struggled to create chances during the first 15 minutes but Braga came within inches of taking the lead midway through the half as Eder's header crashed off the post from Custodio's cross.
Hugo Viana then flashed his shot narrowly wide before Jonny Evans headed straight at goalkeeper Beto from a corner with what was a rare moment of attacking intent for the visitors.
The home side eventually made the breakthrough with five minutes gone in the second half as Alan fired in from the penalty spot following Evans's foul on Custodio.
The game was then interrupted for just over 10 minutes when the floodlights at one end of the stadium went off. Both sets of players were escorted from the pitch before play was resumed.
Robin van Persie was introduced midway through the second half and got United level in the 80th minute when he curled the ball in after a mistake from Beto.
Wayne Rooney grabbed a second from the penalty spot minutes later when he was brought down in the area before Hernandez converted at the third time of asking to seal the win in injury time.