Hunter Pence and Buster Posey hit consecutive homers, and Johnny Cueto struck out seven in seven strong innings for the struggling San Francisco Giants, who beat the San Diego Padres 5-3 Sunday to avoid a three-game sweep.

The Giants snapped a four-game losing streak. They won only twice during the season's opening week.

Pence hit a two-run homer to left field with one out in the third off Clayton Richard (1-1), and Posey followed with an opposite-field shot to right to give the Giants a 5-0 lead. It was the first time this season the Giants hit back-to-back homers.

Cueto (2-0) was working on a three-hit shutout when he walked Travis Jankowski with one out in the sixth and then allowed Wil Myers' homer into the second-floor balcony on the Western Metal Supply Co. Building in the left-field corner. It was Myers' second of the season.