Samardzija (9-13) struck out nine in nine innings, turning in his first career complete game victory.
The right-hander broke a personal four-game winless streak, allowing three runs (two earned) on four hits while walking one.
With the score tied 3-3 in the eighth, Wellington Castillo led off with a single against Jason Grilli (1-5), moved up to third on a pair of outs and came home with the decisive run when DeJesus lined the first pitch he saw into right field.
Alfonso Soriano socked a solo homer, his 27th of the year, as the Cubs clinched their three-game series.
Pedro Alvarez went 2-for-4 with a two-run single for the Pirates, who came into the contest 1 1/2 games out of a National League wild card spot.
Ray Liotta sues skin care company over use of likeness
NBC reportedly holds celebs hostage to Jimmy Fallon's show