Financial terms weren't released, but ESPN has reported the deal to be worth $4.1 million.
Hanrahan and the Pirates worked out a one-year deal last January to avoid arbitration and the right-hander earned his first All-Star Game appearance en route to 40 saves in 44 chances.
The 30-year-old veteran finished 2011 with a record of 1-4 and a 1.83 earned run average in 70 appearances. He also struck out 61 in 68 2/3 innings.
In five major league seasons, including his first two-plus with Washington, Hanrahan has a mark of 17-15 with a 3.92 ERA and 60 saves.