NBA officials approved the swap Friday afternoon by conference call, the Heat said.
The deal also calls for Toronto to get the league's maximum allowed in cash considerations ($3 million) and for the Heat to land a conditional first-round pick to come sometime between 2010 and 2015. It's lottery-protected, essentially meaning the first time the Raptors make the playoffs after this season, their first-rounder goes to Miami.
If Miami does not get that first-round pick in 2010, it will get an additional second-round pick that year. The Heat also get a $4.2 million trade exception, which would allow Miami to make a future trade even if the salaries involved don't match.
"This is a win-win for both Toronto and Miami and we wish J.O. and Jamario the best," said Raptors general manager Bryan Colangelo, who is familiar with Marion from his time with the Phoenix Suns.
The deal was struck mere hours after Marion's dunk with 1.1 seconds to go delivered a 95-93 victory in Chicago in the Heat's final game before the All-Star break.
The Heat and Raptors began discussing a swap featuring Marion and O'Neal in January, but Miami held off in hopes of finding an impact player in better health than O'Neal, who has missed 14 games in his first season in Toronto because of persistent knee trouble.
"I developed an unbelievable relationship with Shawn," Heat star guard Dwyane Wade said in Phoenix, where he's part of All-Star Weekend. "You're sad to lose a friend on and off the court. At the same time, Shawn and I just had this conversation that it's part of the business and we knew it was a possibility."
The Heat, according to NBA front-office sources, made numerous attempts to acquire Dallas swingman Josh Howard with Marion's expiring $17.8 million salary, and more recently tried to use Marion's cap-friendly contract to get into the bidding for Stoudemire.
Sources say that the Suns, though, had made it clear to the Heat in recent days they were not interested in reacquiring Marion -- in spite of the financial benefits -- for the rest of the season.
So Miami proceeded with the deal for O'Neal, which gives Heat president Pat Riley the traditional center he likes but, more importantly, enables Riley to preserve maximum salary-cap flexibility for the summer of 2010.
"It gives us some power down low, which since Shaq left we've been missing," Wade said. "We really need that to compete in the Eastern Conference. Our main thing is we need to get it together fast. Making a trade at this time sometimes makes it tough on teams to get everybody on the same page. Hopefully, we can."
O'Neal makes $23 million next season in the final year of his contract, after which Miami will try to re-sign Dwyane Wade and flank Wade and current rookie Michael Beasley with another free-agent superstar such as Stoudemire or Toronto's Chris Bosh.
The Raptors have been shopping O'Neal since January after it became clear that there was not enough room for Bosh and their marquee offseason acquisition in the same offense.
This deal will enable Toronto to field a more mobile frontcourt trio of Bosh, Marion and former No. 1 overall draft pick Andrea Bargnani, as preferred by Raptors president Bryan Colangelo. In 1999, Colangelo drafted Marion for the Suns with the ninth overall pick.
After more than nine seasons in Phoenix, Marion, along with Banks, was dealt to Miami for Shaquille O'Neal on Feb. 6, 2008. The Raptors' willingness to take Banks in this deal -- as well as give the Heat a conditional first-round pick -- apparently convinced Riley that he could no longer wait.
Neither team has commented publicly on the deal. At All-Star Weekend in Phoenix, Wade had told the Associated Press that he would wait until the deal was officially announced before commenting.
Marion, 30, is averaging 12.0 points and 8.7 rebounds this season while bracing for a trade that has seemed inevitable since last summer, when he and the Heat could not reach terms on a contract extension.
"You've got to get honest with yourself and say if you're going to compete with the big boys, you've got to get somebody in the middle," Riley said.
Marc Stein is a senior NBA writer for ESPN.com. Information from The Associated Press was used in this report.