Sunday was Kids’ Day at Wrigley Field, with an army of tykes allowed on the field to scamper around the bases after the game.

It might well have been Baseball Vagabond Day, as Edwin Jackson and Cody Ransom lifted the Cubs to a 4-1 victory against the Pittsburgh Pirates. The result enabled the Cubs to avert a three-game sweep and to stop a five-game losing streak against the Pirates.

Jackson is 29, and the Cubs became his eighth major-league team when he signed a four-year, $52 million contract with them as a free agent last winter. He brought a 1-8 record and a 6.29 ERA to work with him and admittedly was pressing to justify his salary.

‘‘Maybe I was taking it too serious,’’ Jackson said. ‘‘I was too confined, too locked up, too tight. I told myself to just let it go, have fun and play the game, and whatever happens, happens.’’

What happened was his first victory since May 11. Jackson allowed four hits, struck out eight and walked one in seven innings, easily his most effective outing of the season. He went after the Pirates with live fastballs and hard sliders.

‘‘He threw hard and with conviction,’’ manager Dale Sveum said. ‘‘His slider was 86, 88 miles per hour. That’s where he has to be to pitch [effectively].’’

Ransom is 37, and the Cubs became his eighth major-league team when he arrived on waivers from the San Diego Padres in mid-April. Starting at third base against left-hander Jeff Locke, Ransom broke a 1-1 tie when he lined reliever Justin Wilson’s 2-1 pitch into the bleachers in left-center field for a three-run home run in the seventh.

Wilson ‘‘throws hard, with a little cutter,’’ Ransom said. ‘‘He threw me that when I faced him in Pittsburgh, so I was looking for it.’’

Ransom has hit six homers in 65 at-bats with the Cubs and 27 in 659 at-bats in parts of 11 seasons.

‘‘The difference is more consistent playing time,’’ Ransom said. ‘‘I know if we’re facing a left-hander, I’m more than likely going to be in there.’’

Ransom had an adventuresome day even before his tiebreaking blast. In the third, the Cubs had two on with two outs against Locke when Ransom was picked off second with Alfonso Soriano at the plate to end the inning.

‘‘He had a knuckle-curve grip and I didn’t think he could pick me off with that, so I got a little greedy and wandered too far off,’’ Ransom said. ‘‘He got me.’’