The sides avoided arbitration with Tuesday's deal.
Hanrahan and right-hander Evan Meek are expected to compete to be the closer.
The 29-year-old Hanrahan was 4-1 with six saves and a 3.62 ERA in a career-high 72 games last season. His 100 strikeouts in 69 2-3 innings were the most for a Pittsburgh reliever since Don Robinson had 101 in 1984.
The Pirates also agreed to terms with right-hander Jose Veras and catcher Wyatt Toregas on minor league deals and invited them to spring training.