The Giants took three of four at PNC Park. Pittsburgh has lost 11 of 14, dropped to 5-17 in June and fell five games under .500.
After hitting a key double late in Wednesday night's win, Panik put the Giants ahead 3-1 with his triple in the third inning. Williamson followed with an RBI single.
Williamson connected for his second home run of the season in the sixth.
Albert Suarez (3-1) gave up two earned runs and four hits in five innings.
Suarez threw a season-high 102 pitches in his fourth start of the season while filling in for the injured Matt Cain. He struck out six.
Santiago Casilla struck out three in the ninth for his 16th save.
The Giants' bullpen shut down the Pirates for the second consecutive game. George Kontos, Hunter Strickland, Cory Gearrin and Casilla combined to pitched four scoreless innings a day after the Giants used five relievers to pitch six shutout innings.
Jonathon Niese (6-5) was tagged for five runs in six innings.
Pirates: LF Starling Marte was held out of the starting lineup for the second consecutive game with a sore left foot. He pinch hit in the seventh inning and flied out. ... C Chris Stewart was out after starting Wednesday, his first appearance since being sidelined with a knee injury.
Giants: Jake Peavy (3-6, 5.47 ERA) will start at home when the Giants open a three-game set against Philadelphia. Peavy has a 2.65 ERA in three June starts.
Pirates: Rookie Jameson Taillon (1-1, 3.50 ERA) will make his fourth start to being a four-game home series with the Los Angeles Dodgers. Taillon had his first subpar start the last time out, when he gave up eight hits and four runs in four innings against the Cubs on June 19.