"Trade w/ @knicks is done," the team said via Twitter.
The deal was reported more than a week ago but could not be officially completed until Wednesday.
In return, the Raptors receive Knicks reserves Steve Novak, Marcus Camby and Quentin Richardson. The Knicks are also sending the Raptors a 2016 first-round pick and second-round picks in 2014 and 2017.
Bargnani is coming off an injury-shortened season that was his worst since his second year in the league, and had become a lightning rod for a struggling Toronto team that missed the playoffs this past season for the fifth year in a row.
The Raptors attempted to trade Bargnani this past season before two significant elbow injuries derailed any serious interest. The puzzling Italian centre, who looked so good at times in the 2011-12 season, spent more than half this past campaign on the bench.
The seven-foot, 256-pound centre was drafted first overall by the Raptors in 2006, and went on to average 15.2 points, 4.8 rebounds and 1.3 assists per game over seven seasons in Toronto. The Raptors made the playoffs just once since drafting him.
Bargnani has two years and about $22.2 million remaining on his contract.
Note to readers: This is a corrected story. A previous version had outdated information on Quentin Richardon being signed and traded.Suggest a correction