The Padres have lost eight of nine and are slipping in the race for the second NL wild-card spot. The Padres' loss, along with Cincinnati's 5-3 win over the Marlins on Friday, moved San Diego and Cincinnati into a tie in the wild-card race.
Philadelphia is four games back in the NL wild-card standings.
"We really needed this win," Phillies manager Joe Girardi said. "The bullpen did a terrific job. (Starter) Matt Moore did a terrific job."
The Phillies scored three runs in the third inning against Padres starter Blake Snell. With two out, Jean Segura walked and stole second base. J.T. Realmuto doubled home Segura, and Harper followed with a long home run to right field off an 84 mph slider.
"It's really frustrating overall ... I have to limit the walks," Snell said. "I am really surprised at Harper's at-bat. ... I hung a slider inside, which you never want to do to a lefty."
Trailing 3-0, the Padres scored two in the bottom of third against Moore. One batter after Tommy Pham walked, Manny Machado hit a low line-drive homer that hit the top of the left-field fence and bounced into the stands.
In the sixth inning against Phillies reliever Hector Neris, San Diego loaded the bases with two outs. However, Tommy Pham grounded out weakly to shortstop Ronald Torreyes, ending the threat.
"We just have not been able to cash in with runners in scoring position," Padres manager Jayce Tingler said. "We are trying to play good baseball, that's all we can control. ... This past week didn't go our way, but that doesn't mean it is going to continue. It's going to turn."
Philadelphia added an insurance run in the eighth for a 4-2 lead. Andrew McCutchen hit a double to left field off Emilio Pagan, driving in Segura from first base.
"McCutchen's RBI is the difference in the game," Girardi said. "He was swinging the bat well all night."
Hosmer, who reach based four times via a single and three walks, led off the eighth with a free pass against Phillies reliever Archie Bradley and moved to third on a single to center by Wil Myers. Bradley then struck out Adam Frazier and pinch-hitter Trent Grisham before walking Pham to load the bases.
Bradley was lifted in favor of closer Ian Kennedy, who had to face Fernando Tatis Jr. with the bases loaded.
"You probably couldn't draw up a tougher situation to come in there," Moore said of Kennedy having to face Tatis.
Kennedy hit Tatis in the helmet with a fastball, forcing in a run. Tatis dusted himself off and was not injured on the play.
"It just got away from me," Kennedy said of hitting Tatis.
The next batter, Machado, eventually struck out to end the inning. But during the at-bat, Tingler was tossed for arguing balls and strikes. After the strikeout, Machado was ejected during a heated argument with the home plate umpire. Machado chucked his batting gloves at home plate as he walked back to the dugout.
"I just tried to get ahead of Machado," Kennedy said. "It's nice to get a call to go my way. ... The umpire didn't change the zone all game. As a pitcher, you just have to pitch to it."
Neris (2-5) earned the victory in relief for the Phillies, and Kennedy earned his 20th save by retiring the Padres in order in the ninth.
Snell (6-5) took the loss.
"Every team is going to go through a stretch where you lose a bunch of games," Snell said. "It's all about how you bounce back and fight."
Phillies: CF Odubel Herrera (right elbow swelling) is day to day after he was hit on the right elbow with a pitch on Aug. 19 against the Diamondbacks. ... 1B Rhys Hoskins (strained left groin), who is on the 10-day IL, might return on August 21. Hoskins fielded ground balls and took batting practice on Friday. ... LHP Jose Alvarado (left shoulder impingement), also on the 10-day IL, threw a bullpen session on Friday. Alvarado will throw another session on Sunday.
Padres: Newly acquired RHP Jake Arrieta (left hamstring strain) was placed on the 10-day IL, two days after he exited his first Padres outing in the fourth inning of San Diego's loss to the Rockies on Aug. 18. ... RHP Yu Darvish (lower back tightness) threw a bullpen session on Friday, his first since he exited his start on Aug. 12. Manager Jayce Tingler would not put a timetable on a potential Darvish return. ... RHP Chris Paddack (left oblique strain) threw off the front slope of the mound on Wednesday, then went through an intensive bullpen session on Friday in which he threw 25 pitches. ... .RHP Dinelson Lamet (right forearm inflammation) threw a bullpen session on Thursday, his first since a hip he incurred in mid-August. Lamet, who has spent four stints on the IL with elbow/forearm related issues this season, is being prepped to return as a reliever in September. ... .LHP Drew Pomeranz (left flexor tendon tear) was moved to the 60-day IL and is not expected to return until next season.
Phillies: RHP Aaron Nola (7-7, 4.48 ERA) takes the hill.
Padres: RHP Joe Musgrove (8-8, 3.11 ERA) starts in the second game of the three-game series.
Machado hits home run that exits at 119.6 mph, is later ejected
Manny Machado hits a big home run and later argues with an umpire over a strike call, leading to his ejection.