"When you look at it how well we've played, it's not always going to be the way you want it to be," said Astros manager Bo Porter.
"That's a part of maturity, to have games like that and put it behind you and move on to the next day. You can't have a bad today ruin a great tomorrow."
Astros second baseman Jose Altuve, who leads the Major Leagues with 90 hits, missed the game with a right hand injury sustained in Thursday's home win against Arizona by being hit by a pitch. He's listed as day to day.
"It had some effect on us," said Astros first baseman Jon Singleton, whose fourth-inning leadoff home run was one of the few bright spots for the Astros (31-38). "He's a good addition to our ball club."
Besides Singleton's fourth home run in only 11 games as a Major Leaguer, and his second homer in as many games, the Astros' other hits were consecutive singles by Chris Carter and Robbie Grossman in the second off Cobb, and Jason Castro's leadoff double in the ninth off Kirby Yates.
Cobb (2-4) outpitched Collin McHugh (4-4), who needed 100 pitches in only five innings. Cobb, who snapped a three-game losing streak, held Houston to one run and three hits in 6 1/3 innings. His 11 strikeouts were two shy of his career high.
"He was just making good pitches, he kept the ball down in the zone," said Singleton. "He kept us guessing."
The Astros struck out 16 times with right fielder George Springer going 0-for-4 with four strikeouts. Singleton struck out three times.
"He threw a great game," said Porter. "He had a plus, plus changeup. As much as our guys wanted him to get the ball up, he took advantage of our aggression."
And it wasn't just Cobb getting strikeouts. Joel Peralta, the Rays' third pitcher, struck out all three batters he faced, the top of the Houston order in the eighth inning. But it was Cobb who got it all started for the Rays (26-42). Friday was the first time the Rays won a game started by someone other than former Astro Erik Bedard since May 25 vs. Boston.
"Before the game I looked at video," said Cobb. "The biggest thing that stood out to me is how aggressive this team is. They're really hunting and looking for the fastball.
"My gameplan was to go out there and show them early that I'm going to be throwing off-speed in and out of the zone."
Added Rays manager Joe Maddon: "It's wonderful to see him have that kind of game tonight in spite of the fact that he didn't have everything going. I think his changeup was the pitch today that really got him through the whole thing."
The Rays scored two runs in each of the second, fifth and ninth innings and totaled 11 hits. Ben Zobrist's two-run triple in the fifth snapped a 0-for-26 streak with runners in scoring position. The Rays got a two-run double from Matt Joyce in the second off McHugh, and a two-run single by Evan Longoria in the ninth off Kyle Farnsworth, who allowed four hits in the inning.
McHugh allowed four runs (three earned) and five hits with six strikeouts and three walks.
"My fastball wasn't very good," said McHugh. "I'm not happy with my fastball command. Three walks is not good."
Cobb was relieved with one out in the seventh and Matt Dominguez on first base after Desmond Jennings ran halfway up Tal's Hill in center field to make a catch on a ball driven more than 400 feet by Carter for the first out.
Brad Boxberger, who relieved Cobb and walked Marwin Gonzalez after striking out Grossman, put down a Houston threat in the seventh. Boxberger got Jonathan Villar looking at strike three for the third out with runners at first and second.
Singleton smacked the first pitch he saw to open the bottom of the fourth off Cobb. Singleton's homer to left field cut the deficit to 2-1.
Joyce's two-run double in the second scored James Loney, who reached first base after shortstop Villar dropped a popup, and Zobrist, who followed Loney with a double.
Josh Zeid, who was brought up from Triple-A Oklahoma City on Friday, relieved McHugh to start the sixth. Zeid turned a double play in the inning by catching Yunel Escobar's sacrifice bunt attempt, and then doubling off Joyce at first base on a throw to Singleton. Zeid pitched two scoreless innings.