In that game, he gave up three runs in six innings, striking out seven, and hitting a triple in his first at-bat. He did not receive a decision, but the Nationals defeated the Mets 6–5. One week later on August 4, 2007, Hanrahan got his first big league victory over the St. Louis Cardinals, allowing one run and six hits in 5 innings, and helping his cause by hitting a two-run double. In late 2008, after the trades of Jon Rauch and Luis Ayala, Hanrahan was named the closer. He finished the season with nine saves as well as striking out 93 batters in 84 innings pitched. He competed on Team USA for the 2009 World Baseball Classic after an injury to BJ Ryan. On June 30, 2009 the Nationals traded Hanrahan and Lastings Milledge to the Pittsburgh Pirates for Nyjer Morgan and Sean Burnett. Pittsburgh Pirates On July 9, 2009, Hanrahan earned a win for the Nationals while on the Pirates roster when Washington beat the Houston Astros in the bottom of the 11th inning in the completion of a game from May 5 because he was the pitcher of record, recording the final out for the Nats in the top of the 11th. In 2010, Hanrahan struck out 100 batters in 69 innings and became the Pirates closer at the end of the season. On February 16, 2011, Pirates manager Clint Hurdle announced Hanrahan as the opening day closer for the Pirates. He was named the Delivery Man of the Month Award winner for June 2011. Hanrahan was named to the All-Star game in 2011, garnered a career high 40 saves in one season, and finished the year with a 1.83 ERA. On January 16, 2012, Hanrahan agreed to a one-year, $4.1 million deal that included incentives with the Pirates to avoid arbitration. On July 1, Hanrahan and teammate Andrew McCutchen were both named to the All-Star Game's National League roster for a second consecutive year. At the time of his selection, Hanrahan was third in the National League in saves (20) and had converted in 22 save appearances. "It definitely feels good to come back a second time. Sometimes, people can get in on a fluke. To get voted in by my peers, again, is a huge honor." Boston Red Sox On December 26, 2012, Hanrahan was traded to the Boston Red Sox (along with Brock Holt)