Boston will receive Hanrahan and infielder Brock Holt from Pittsburgh, which will get pitchers Mark Melancon and Stolmy Pimentel, infielder Ivan De Jesus and utility player Jerry Sands in return.
Hanrahan had 36 saves in 63 pitching appearances last season with the Pirates. No other player on the team had more than three saves in 2012. He became the Pittsburgh main closer in 2011, piling up 40 saves that season, and was selected to the National League All-Star team each of the last two years.
He has a 22-17 record with a 3.74 earned run average and 96 saves in 353 appearances for Washington and Pittsburgh since 2007.
Holt made his major-league debut in September, hitting .292, picking up 19 hits in 24 games.
Melancon was 0-2 with a 6.20 ERA for Boston, after earning 11 saves and a 0.83 ERA in 21 appearances at Triple-A Pawtucket. He played in 147 major league games over four seasons.
Pimentel was 6-7 with a 4.59 in 22 Double-A games in 2012.
De Jesus has played 31 major-league games and Sands has appeared in 70 in their careers.
Jordana Brewster on Paul Walker: 'He was an enormous presence in my life'
Benedict Cumberbatch's dramatic reading of R. Kelly lyrics is just what you need