Bailly was stretched off just nine minutes after coming on as a half-time substitute in only his third game back after missing the Africa Cup of Nations following knee surgery.
Earlier, Anthony Martial had put United in front during a bad tempered first half before Lucas Moura's deflected effort threatened to send the game to penalties only for Gomes to finish off a well-crafted move to ensure United ended their tour of Australia and the Far East on a high.
All nine of United's goals during the tour have been scored or assisted by an academy graduates.
On a heavy pitch at the Hongkou Stadium, United went ahead on 21 minutes thanks to Martial's second goal of the summer.
The Spurs goalkeeper should have done better but it was a deserved slice of luck for Martial, who had already hit the inside of the post with a superb strike from the left hand corner of the penalty area.
Having spent much of the last three seasons on the wing, it was another game at centre forward for Martial and judging by this tour that's where he will play next season.
On a hot, sweaty night in Shanghai the game threatened to boil over during a feisty first half.
Dele Alli clattered Aaron Wan-Bissaka and Scott McTominay before Moussa Sissoko appeared to stamp on Daniel James after a heavy challenge on the United winger in the corner. Pereira was then booked for a late tackle on Harry Kane.
Ole Gunnar Solskjaer made 11 changes at half-time while Mauricio Pochettino made six and after Bailly's injury, Lucas Moura levelled for Tottenham on 65 minutes.
The Brazilian's shot took a deflection leaving Sergio Romero helpless as the ball crawled over the line.
It looked like penalties would be needed to separate the teams but 10 minutes from time, 18-year-old Gomes bounced the ball off Juan Mata and expertly finished into the far corner to extend United's perfect record this summer to four wins from four.
Solskjaer's side jetted back to Manchester immediately after the final whistle and will complete their preseason preparations with games against Kristiansund in Oslo and AC Milan in Cardiff.