Bourque is the 26-year-old son of Ray Bourque, the Hall-of-Fame defenseman who spent 21 seasons with the Bruins.
The deal was announced by Bruins general manager Peter Chiarelli on Saturday.
Bourque appeared in 73 games for Hershey of the AHL, and scored 27 goals. He was drafted 33rd overall by the Capitals in the 2004 NHL draft. In 2009-10, Bourque appeared in 20 games for the Pittsburgh Penguins.
Hamill played in 16 games for Boston this season.