SAN FRANCISCO (AP) Jonathan Schoop hit a three-run homer in the ninth inning and the Baltimore Orioles overcame a six-run deficit to give the struggling San Francisco Giants another deflating loss, 8-7 on Sunday.

Matt Wieters had a career-best five hits, including a triple, and the Orioles won for the third time in four games and concluded a 10-game trip with an even record. Baltimore trails Toronto by half a game in the AL East.

Schoop homered off Santiago Casilla (2-4) with two outs after Manny Machado singled and Mark Trumbo walked. Baltimore trailed 7-1 after six innings but got two runs in each of the seventh and eighth innings.

More from FoxSports

The Giants led the NL West by 6 1/2 games at the All-Star break but have gone 9-18 since. They entered Sunday with a one-game lead over the Dodgers.

Brad Brach (7-1) pitched a scoreless eighth inning for Baltimore.