The All-Star slugger underwent arthroscopic surgery on Sunday morning, and he is expected to miss four to six weeks.
The procedure was performed at 7 a.m. ET by team physician, Dr. Lee Kaplan, in Miami.
Stanton had "loose bodies" removed from his right knee.
An MRI exam taken on Tuesday revealed Stanton had some fragments in his knee that were hindering him when he ran. The 6-foot-5, 250-pound slugger initially felt his knee lock up in the eighth inning on Monday night at Milwaukee.
After the MRI was taken, Stanton attempted to cope with the discomfort and be able to participate in Monday's State Farm Home Run Derby and Tuesday's All-Star Game in Kansas City.
The 22-year-old right fielder missed four straight starts before returning to the lineup on Saturday at St. Louis. He played two innings in the field, had one at-bat, but was lifted for a pinch-hitter in the third inning.
After being taken out, Stanton didn't stay for the rest of the game. Immediately, he was making plans to head back to Miami. The right fielder now will start to recover, and the team is hopeful that he can be back in early August to help them make a playoff push.
In 80 games, Stanton paces the Marlins with 19 home runs and 50 RBIs. He's batting .284 with a slugging percentage of .554.
Justin Ruggiano is expected to get plenty of opportunity in right field with Stanton out. On Friday, the Marlins will get Emilio Bonifacio back from the disabled list.
Bonifacio went on the DL on May 20 with a sprained left thumb. He had surgery on May 25 to repair a torn ligament. The speedster is currently playing in rehab-assignment games, and he is expected to replace Stanton on the roster.
On July 4, the Marlins acquired first baseman Carlos Lee in a trade with the Astros for Matt Dominguez and Rob Rasmussen. The hope was to have Lee and Stanton anchoring the heart of the order.
"Stanton is such an imposing force in the lineup," team president David Samson said. "Lee was brought in to combine him with Stanton in the lineup. Now, it's sort of back to where you were. But Giancarlo will be back, and he will be back in time to help us.
"We're not nearly out of it, the second Wild Card and the division."