Ramirez smoked an RBI double off reliever Chris Hatcher as the Pirates (88-60) snapped a four-game losing streak. They also remained a game ahead of the Chicago Cubs in the wild-card race. Pittsburgh is four games back of the St. Louis Cardinals in the chase for the National League Central crown.
Liriano delivered in his finest performance of the season.
"Frankie pitched an outstanding ball game," manager Clint Hurdle said. "It was two real strong pitching performances. Frankie gave us just what we needed."
Liriano (11-7), who is 4-0 in five career starts against Los Angeles, retired 16 straight batters at one point after giving up a two-out double to third baseman Justin Turner in the first inning.
"Everything felt great. I was able to throw any pitch in any location," said Liriano, who struck out nine and limited Los Angeles to five hits with two walks in seven innings. "Having a good fastball today helped me with the breaking stuff. It was a great day and we got the win."
Pirates catcher Francisco Cervelli said Liriano mixed his pitches with maximum effect.
"Today, everything was working well," Cervelli said. "They came out aggressive, too. He's a guy that strikes a lot of people out, so he makes hitters chase a lot of pitches (such as) the slider and fastball. He was great."
Cervelli also said it felt good to end the losing streak.
"It's been tough the last four days, but we're back on track," Cervelli said. "This is not over. We want to win the division."
Despite the loss, the magic number for National League West-leading Dodgers (85-61) to clinch the division title fell to seven after the San Francisco Giants were blanked 6-0 by the Arizona Diamondbacks earlier in the day.
Kershaw (14-7) lost for the first time in 14 outings. He hadn't been dealt defeat since the Miami Marlins beat him and the Dodgers 3-2 on June 27.
Kershaw, who had a four-game winning streak end, allowed three runs on seven hits with eight strikeouts and two walks in seven-plus innings. Kershaw has 272 strikeouts for the season, the fourth best mark in Los Angeles history.
Catcher A.J. Ellis ripped a run-scoring double to left to plate third baseman Alex Guerrero to knot the score at 2 apiece in the seventh. However, Liriano was able to work out of a jam, inducing pinch-hitter Austin Barnes to ground into an inning-ending double play.
Pittsburgh closer Mark Melancon worked a 1-2-3 ninth for his major league-leading 47th save. He also set a new franchise mark for saves in a season, eclipsing Mike Williams' record established in 2002.
Center fielder Andrew McCutchen hit a two-run double in the third inning to give the Pirates the lead until the seventh.
Turner left the game after the sixth inning with left knee soreness.
Dodgers second baseman Howie Kendrick, who was activated Friday after missing 34 games with a left hamstring strain, lined a single down the right-field line, scoring left fielder Justin Ruggiano, for a 1-0 Los Angeles with no outs in the first.
In the third, McCutchen' s two-run double to right drove in shortstop Jordy Mercer and Liriano, both of whom reached on singles, for a 2-1 Pittsburgh advantage.
"They've got a good club, up and down," said Dodgers manager Don Mattingly, whose club has dropped four of the five games against the Pirates this year, including a sweep at PNC Park on Aug. 7-9. "They've given us and the rest of this division trouble all year. I look at these guys as one of the better clubs we've played all year long. Obviously, the record shows it. They're a handful."
NOTES: The Dodgers continued to lead the National League with 173 home runs entering Saturday's contest. Los Angeles has not led the NL in homers since hitting 146 in 1983. ... The Pirates were 74-1 when leading after eight innings heading into Saturday's game. ... Dodgers INF Chase Utley worked out at 3B again. With 2B Howie Kendrick returning from a hamstring injury, Utley is expected to get occasional starts at 3B and 1B to keep his bat in the starting lineup. ... Pirates RHP Gerrit Cole (16-8, 2.60 ERA), the former UCLA star and Southern California native, will face Dodgers RHP Mike Bolsinger (6-3, 3.13 ERA) in the series finale Sunday.