Ohlendorf (7-6) allowed only four hits and struck out eight without issuing a walk. Matt Capps picked up his 18th save of the season after pitching a hitless ninth inning.
The Pirates have won five of their last seven games. The victory gave the Pirates a 14-13 mark for the month, their first winning record in June since 1996.
Geovany Soto had two hits for the Cubs, who have lost seven of their last nine games.
Chicago starter Ted Lilly (7-6) gave up three runs on eight hits, while striking out seven in seven innings.