Alex Dickerson and Mauricio Dubon also went deep for the Giants, who erased a 5-1 deficit to win for the seventh time in nine games.
First-year San Francisco manager Gabe Kapler had to use five pitchers to keep his club on a roll and got another big night from the offense.
Donovan Solano had three hits and scored twice. Brandon Belt singled twice and had two RBIs. The Giants have scored four or more runs in 10 consecutive games for the first time since 2007.
''We have guys that can hit the ball out of this ballpark, out of other ballparks,'' Kapler said. ''One of the things that we continue to say and that we've seen play out is that we're not out of games so we can handle an early deficit and trust that we have the guys who can hit singles but also hit balls in the gaps and sometimes in the seats.''
J.P. Crawford drove in three for the Mariners.
Ruf's blast off lefty reliever Anthony Misiewicz (0-2) was his third of the season and the fourth of his career as a pinch-hitter. Ruf, in his first year back in the majors after playing three seasons in Korea, was called on to hit for Dickerson, who homered off right-hander Brady Lail in the third.
''It's a lot of fun mainly because most of the time it's not going to work out that way where you're going to get a home run from the left side and then Ruf's going to come in and pinch hit and hit a big home run,'' Kapler said. ''That just doesn't happen that frequently, so when it does work out in your favor you remember how often it goes the other way.''
Dickerson, who was questionable before the game after fouling a ball hard off his right knee on Monday, praised Kapler for the move.
''That was awesome,'' Dickerson said. ''To make a move and the guy immediately does the best thing you can do and hits a home run . it was awesome production.''
Dubon also homered off Lail.
Seattle manager Scott Servais was ejected in the eighth inning by home plate umpire John Libka for arguing balls and strikes.
''The first one was definitely low and the second one was lower than that,'' Servais said. ''Got to be better.''
Tyler Rogers (2-3) retired three batters to win. Tony Watson pitched the ninth for his second save.
Giants starter Logan Webb allowed five runs and six hits in five innings.
Mariners starter Ljay Newsome was knocked out of the game after getting hit near the wrist on his pitching hand by a 100 mph line drive from Brandon Crawford leading off the second. The ball ricocheted off Newsome's hand high into the air and was caught by Crawford at shortstop for an out. Newsome grimaced and repeatedly tried to flex his hand before Servais and a team trainer came out.
''Actually feels pretty good right now. I have full motion in it,'' Newsome said. ''I've been hit plenty of times but I've never come out of a game.''
The Giants recalled OF Luis Basabe from the alternate training site in Sacramento and optioned IF Daniel Robertson down.
Mariners: Newsome underwent X-rays which were negative. He is day to day.
Giants: Pablo Sandoval was at third base for another game as regular starter Evan Longoria deals with soreness in his right glute. Longoria entered the game as a defensive replacement in the ninth. ... RHP Jeff Samardzija (inflamed throwing shoulder) will throw a simulated game Thursday at the team's Sacramento alternate site. ... LHP Drew Smyly, sidelined by a sprained index finger on his pitching hand, is still expected to be activated in the next couple of days.
Seattle's Nick Margevicius (1-2, 3.86) and San Francisco's Tyler Anderson (1-3, 5.18) pitch the series finale in a matchup of lefties Wednesday. Margevicius will make his fifth start after beginning the season in the bullpen. Anderson's last three starts all came against Arizona.
More AP MLB: https://apnews.com/MLB and https://twitter.com/AP-Sports
Copyright 2020 STATS LLC and Associated Press. Any commercial use or distribution without the express written consent of STATS LLC and Associated Press is strictly prohibited.