The Pittsburgh Pirates have agreed to a two-year deal with All-Star Ryan O'Hearn to boost their struggling offense.