Over the past two seasons, Hanrahan had 76 saves, fourth most in the National League, and a 2.24 ERA. Last season, he was 5-2 with a 2.72 ERA and 36 saves.
The six-year veteran will take over the closer's role that Alfredo Aceves struggled in most of last season before giving way to Andrew Bailey, who had missed most of the season with a right thumb injury.
In his first season with Boston, Bailey was 1-1 with a 7.04 ERA and six saves in nine opportunities over 19 games.
Manager John Farrell has talked with Hanrahan and Bailey and told them that Hanrahan will be the closer, although "we see Andrew as playing a very important role," O'Halloran said.
"I got excited" when he learned of the trade, Hanrahan said. "Obviously, the Red Sox have a great history and tradition and it's a huge sports city."
In six seasons, 2 1/2 with the Washington Nationals and 3 1/2 with the Pirates, he's 22-17 with a 3.74 ERA and 96 saves in 117 chances. His best season was 2011 when he went 1-4 with a 1.83 ERA, 40 saves in 44 opportunities and just 16 walks in 68 2-3 innings. His control slipped last season when he walked 36 in 59 2-3 innings.
Hanrahan said hamstring and ankle problems affected his pitching mechanics.
"I don't think the walks are going to be a concern," he said. "I feel good going to spring training."
Hanrahan said he's never been to Fenway Park, but O'Halloran doesn't think he'll have trouble adjusting to the American League.
"Joel Hanrahan has the stuff to pitch anywhere," he said.
Holt spent most of last season at Double-A Altoona, then hit .292 in 24 games with the Pirates, all in September.
Melancon was 0-2 with a 6.20 ERA in 41 relief appearances in his only season with Boston. Pimentel spent the season at Double-A Portland. Sands and DeJesus were obtained in a trade that sent Gonzalez, Josh Beckett and Carl Crawford to the Dodgers on Aug. 25.