BALTIMORE (AP) It was one of those rare days when everything went right for the Houston Astros.
Houston took an early lead and added to it late. The starting pitching was solid. The bullpen was nearly perfect.
The result was a 5-2 victory over the Baltimore Orioles on Sunday that enabled the young Astros to avert a three-game sweep.
''Overall, a good team win,'' manager Bo Porter said.
Jason Castro and Marc Krauss homered to account for all of Houston's offense, and Jarred Cosart (2-3) allowed two runs over six innings for the Astros, who had lost seven of eight before ending Baltimore's five-game winning streak.
Castro hit a three-run homer off Chris Tillman (3-2) in the first inning, and the Astros made the advantage stand up.
''When we can come out and score early, that's really when we're at our best,'' Castro said. ''It kind of gives some of the young staff a little bit of a breather from the beginning.''
It was 3-2 before Krauss connected against T.J. McFarland with a runner on in the seventh.
''Those are the runs we have not been able to get,'' Porter said. ''Those tack-on runs that give you an extra cushion, make it a three-run lead instead of a one-run lead. That was a huge home run.''
Houston is 11-11 when it hits a home run and 1-15 when it doesn't.
Although the Astros' bullpen came in with a 6.21 ERA, Tony Sipp struck out five in two perfect innings and Chad Qualls worked a hitless ninth for his second save.
''I have confidence no matter who they put in behind me that they can get the job done,'' Cosart said.
Jose Altuve had three hits for the Astros, who improved to 6-12 against the Orioles - including 2-10 at Camden Yards. Everything seemed to fall into place for the team with the worst record in the major leagues.
''We've played some good baseball the last two days,'' third baseman Matt Dominguez said. ''Pitched the ball well, got some timely hits. Hopefully that can give us a jumpstart.''
Adam Jones drove in both Baltimore runs, giving him 501 RBIs in 981 career games.
Tillman gave up three runs, four hits and a season-high five walks in five innings. The right-hander settled down after issuing three walks and a home run in the first inning, but needed 105 pitches to get 15 outs.
''It was a struggle for me. Fastball command wasn't there for me from the get-go,'' Tillman said. ''It was a battle all day.''
Before the game, the Orioles activated Chris Davis (strained left oblique) from the 15-day disabled list and put catcher Matt Wieters on the DL with a strained right elbow. Davis went 2 for 4 in his first game since April 25.
''Felt good,'' Davis said. ''Timing is a little off, little in-between. But it was definitely good to be in there, moving around again.''
Houston took a 3-0 lead before Tillman retired a batter. After Altuve and Dexter Fowler walked, Castro hit the right-hander's next pitch over the center-field wall. Tillman has yielded seven first-inning runs this season, his most in any inning.
''He kept us in the ballgame and threw some zeros up after that,'' manager Buck Showalter said. ''But it wasn't what he's capable of or what we've come to expect. Or more importantly, what Chris has come to expect.''
Jones hit a two-run single to get Baltimore to 3-2 in the third.
A double by Davis in the fifth put two runners in scoring position, but Jones struck out before Nelson Cruz flied out.
NOTES: The Orioles were denied consecutive three-game sweeps for the first time since 2005. They won three in a row at Tampa Bay before facing the Astros. ... The game drew 45,944 fans, the second sellout of the season at Camden Yards. ... Baltimore's Nick Markakis singled in the third inning to extend his hitting streak to 18 games, one short of his career high. ... Tillman's 399th and 400th career strikeouts came against George Springer in the first and third. ... Houston's Alex Presley snapped an 0-for-14 skid with a sixth-inning single. ... Bud Norris takes the mound for Baltimore on Monday night in the opener of a three-game series against Detroit. The Astros return home to face Texas. ... Since coming to Houston from the Padres organization, Sipp has retired all 12 batters he's faced with seven strikeouts.