SAN FRANCISCO — Yu Darvish and two relievers combined on a five-hitter, Cody Bellinger hit his 37th home run and the Los Angeles Dodgers won back-to-back games for the first time in nearly three weeks, beating the San Francisco Giants 4-1 on Wednesday night.

The win lowered the Dodgers’ magic number to seven for clinching the NL West crown. Los Angeles secured at least a wild-card berth in the playoffs Tuesday night with a victory that ended its 11-game losing streak, the club’s longest since moving to the West Coast in 1958.

Darvish, acquired from Texas at the July 31 trade deadline, was 2-3 with a 5.34 ERA in six previous starts with Los Angeles but was crisp in his first career outing against San Francisco. The All-Star right-hander pitched three-hit ball over seven innings, struck out five and allowed only three runners while facing one batter more than the minimum.

Rancho Cotate grad Brandon Morrow pitched the eighth and Walker Buehler allowed a run in the ninth before striking out Denard Span to end it.

Ten days after breaking Mike Piazza’s franchise rookie record for home runs, Bellinger tied Al Rosen (1950) and Albert Pujols (2001) for fifth-most by a rookie in major league history with a two-run drive into McCovey Cove in the fifth inning.

Bellinger’s home run on a 2-0 pitch from Matt Moore put the Dodgers up 4-0 and helped Darvish get his own season back on track after three consecutive losses.

It’s the Dodgers’ first series win in San Francisco since September 2014. They needed it, too, after a two-week funk that included a stunning 16 losses in 17 games by the team with the best record in the majors (94-52).

Los Angeles gets an off day Thursday before opening a three-game series in Washington against the NL East-leading Nationals, who have the second-best record in the NL.

Moore (5-14) allowed four runs with five strikeouts and three walks.

The Dodgers made several big defensive plays. Darvish started a double play in the first inning, and Kike Hernandez sprinted in from left field to catch Buster Posey’s fly ball and then threw on the run to first base to double up Jarrett Parker to end the seventh. Third baseman Justin Turner also made a sliding catch of Posey’s popup behind the mound in the eighth.

TRAINER’S ROOM

Giants: Pablo Sandoval started at third base and committed an error after Ryder Jones was scratched late because of an illness. Jones struck out swinging as a pinch-hitter in the sixth.

UP NEXT

Dodgers: LHP Alex Wood (14-3, 2.81 ERA) pitches against the Nationals for the first time since 2015 when the teams begin a three-game series in Washington on Friday.

Giants: RHP Jeff Samardzija (9-13, 4.47) faces Arizona on Friday in the opener of a three-game series. Samardzija is 3-3 in his career against the Diamondbacks but has lost to them twice this year.