New York also received cash from Pittsburgh as part of the deal for a player to be named later or cash considerations.
It's the second time Hechavarria was traded in the past month, as the Pirates previously received him in a swap with the Tampa Bay Rays in early August.
The 29-year-old Cuba native has posted a .254/.287/.342 triple-slash line with four home runs across 76 games this season. Those numbers are right in line with his career averages.
Hechavarria is more known for his glove than his work at the plate. His plus-22 defensive runs saved figure since his 2012 debut with the Toronto Blue Jays ranks seventh among shortstops during that span, per FanGraphs.
He'll likely serve as a late-inning defensive replacement for Gleyber Torres until starting shortstop Didi Gregorius returns from a heel injury. He also has limited experience at third base (18 games) and second base (eight) during his MLB career.
Hechavarria will need a strong finish to the season or further injury woes for the Yanks if he's going to make the team's postseason roster.