Ramirez's 18th homer, a two-run shot, capped Chicago's four-run rally in the inning. He leads the majors with 13 homers since June 24.
"We were down 2-0 in that inning," Ramirez said. "It was a big inning for us. I'm glad I came through.
"Anytime you get men on base you should capitalize it, you should score some runs," he said.
Soriano started the inning with his 15th of the season -- first since June 19.
"I hadn't homered in a month, so it was good for me and good for the team because we got the win," Soriano said. "I just feel like I was thinking too much."
Cubs starter Carlos Zambrano (7-5) won for just the second time since May 26 and improved to 16-8 against Houston, the most wins against the Astros by an active pitcher.
Zambrano went six innings, allowing nine hits and two runs. He struck out three and walked one. It was Zambrano's first win since he returned from a DL stint caused by lower back tightness.
"I feel 100 percent," Zambrano said. "My sinker was good. Nothing was bothering me. I'm back on track."
The Cubs snapped Houston's five-game winning streak at Wrigley Field, beating the Astros at home for the first time in four games this season.
Houston's Bud Norris (5-7) took the loss in his first career start at Wrigley Field. He gave up nine hits in 6 1/3 innings, allowing four runs and striking out five.
"I didn't execute that pitch to Ramirez," Norris said. "Trying to get a fastball up and in, definitely left it out and over, and that's what a good hitter does to it."
Michael Bourn had three hits and two stolen bases.
Five Cubs relievers combined to throw three scoreless innings.
"It's easy to manage when everybody comes in and does their job," Cubs manager Mike Quade said.
Sean Marshall pitched a perfect ninth for his third save. Carlos Marmol, the Cubs' closer for most of the season, struck out the only two batters he faced in the eighth inning. After his sharp outing, Marmol is now slated to close again.
"Marmol was sharp," Quade said. "Maybe he's ready to finish up a game (Saturday), hopefully. He's a closer, and he pitched like it."
Marmol said he is ready to return to ninth-inning duty.
"I thought (Quade) was going to put me in today," Marmol said, laughing. "He's the boss, he can do whatever he wants to do. I'm ready whenever.
"I feel very good right now. I'm getting my confidence back."
The Astros failed to capitalize on some early opportunities and stranded eight runners.
"We weren't able to capitalize," Astros manager Brad Mills said. "We had 10 hits, but it seemed like they didn't come quite when we would have liked if we had our choice."
The Astros again loaded the bases with no outs in the third. Norris and Bourn singled and Zambrano hit Jose Altuve in the shoulder with a pitch.
Zambrano fell behind Hunter Pence 3-0, but Pence lined sharply to shallow left. Lee flied out, leaving the bases loaded for Wallace, who was also retired on a fly ball.
"I got lucky on the pitch to Pence," Zambrano said. "He hit it hard but right at Soriano."
The Cubs also struggled early. Soriano led off the third with a double into the left-field corner. With one out, he was caught in a rundown on a comebacker hit by Zambrano. Chicago also squandered Ramirez's leadoff double in the fourth.
Houston went ahead 2-0 in the fourth when Bourn singled home Barmes.
Ramirez then hit a two-run homer into the left-field bleachers, putting the Cubs up 4-2. The inning was kept alive by Zambrano's drag bunt, which skipped past Norris toward second baseman Altuve.
A crowd of 39,855 showed up at Wrigley Field for the matchup between the teams with the National League's worst records.
Houston activated outfielder Jason Bourgeois from the 15-day disabled list and optioned outfielder Brian Bogusevic to Triple-A Oklahoma City. Bourgeois was on the DL since June 29 because of a strained right quad. Bourgeois struck out as a pinch-hitter in the eighth. ... Henry Sosa, acquired by the Astros from the San Francisco Giants for infielder Jeff Keppinger on Tuesday, threw seven shutout innings in his debut with Double-A Corpus Christi on Thursday night. ... Quade will wait to for this weekend series to unfold before naming a starting pitcher for Tuesday at Milwaukee. Rodrigo Lopez, who has three straight quality starts, is the likely choice. ... Ramirez hit his 231st homer with the Cubs, tying Gabby Hartnett for sixth on the club's career list. ... The Cubs snapped a nine-game streak with at least one error, their longest since June 4-13, 1987. The Cubs have 87 errors, 15 more than the Astros, who have the second most in the NL.