Hansen's collegiate career began at St. John's University in, where he pitched for the St. John's Red Storm. Hansen selected St. John's over Columbia University, Yale University, and Hofstra University. While he struggled during his freshman campaign in 2003, Hansen began to establish himself as a closer during his sophomore season in. In 2004, Hansen played collegiate summer baseball for the Harwich Mariners of the Cape Cod Baseball League. A league all-star, he posted 10 saves and 41 strikeouts in 22.1 innings pitched without allowing an earned run. In 2018, he was inducted into the CCBL Hall of Fame. Hansen posted a 3-2 record with 14 saves in his junior season of 2005, registering 85 strikeouts in 64 innings pitched, a 1.68 ERA, and was named a first-team All-American by Baseball America.
Pro career
Boston Red Sox
With the 26th pick in the first round of the 2005 Major League Baseball Draft, the Boston Red Sox selected Hansen and signed him to a four-year deal valued at $4 million. The Red Sox added him to the 40-man roster, assigning Hansen to a conditioning stint in Fort Myers before sending him to the Double-A Portland Sea Dogs. Hansen joined the Boston Red Sox as a late season call-up, making his major league debut on September 19 against the Tampa Bay Devil Rays. Hansen struck out the first man he faced, pitching a perfect inning with two strikeouts, and would make three more appearances before the end of the season. After starting the season in Portland and Pawtucket, Hansen was recalled on June 6 by the Red Sox. On June 26, Hansen earned his first major league win in an extra-inning game against the Philadelphia Phillies. On August 20, Hansen entered a tie game against the New York Yankees in the 10th inning only to allow a game-winning home run to Jason Giambi and a two-run home run to Jorge Posada. Hansen would end the season with a 6.63 ERA. During spring training for the season, manager Terry Francona suggested that the team may have rushed Hansen to the majors too quickly. In 2007 at Triple-A Pawtucket Red Sox, he went 3-1 with a 3.86 ERA but did not get a promotion to the eventual World Series Champion Red Sox. Hansen also played in the developmental Arizona Fall League to get extra work in after missing some of the season with forearm tenderness. During the off-season, Hansen underwent surgery in the hopes of correcting the sleep apnea condition that may have affected his stamina and pitching performance. Hansen reported to Red Sox spring training in and initial reports suggested that the team was impressed with his performance. On July 31, 2008, Hansen was traded to the Pittsburgh Pirates along with Brandon Moss in a three-team deal that sent Manny Ramirez to the Los Angeles Dodgers and Jason Bay to the Boston Red Sox.
Pittsburgh Pirates
On August 27, 2008, the Pirates optioned Hansen to AAA. This move was made after Hansen allowed four earned runs without recording an out against the Chicago Cubs the previous night. Hansen was recalled to the Pirates on September 2. In 2009, Hansen was diagnosed with brachial plexus neuropathy, a rare condition causing pain, weakness, and numbness in the arms, shoulders, and upper back. Recovery is usually complete, but can take as long as five years. Hansen was able to pitch in a limited number of minor league games in 2010, but was not at full effectiveness, and the Pirates released him in early 2011.