Cabrera leads the National League with 159 hits and is second in batting average behind Pittsburgh's Andrew McCutchen. Cabrera's penalty is the first for a high-profile player since last year's NL MVP, Ryan Braun, had his suspension overturned by an arbitrator last winter.
Major League Baseball said Cabrera tested positive for the banned performance-enhancing substance in violation of the drug agreement between owners and the players' association.
"My positive test was the result of my use of a substance I should not have used," Cabrera said in a statement released by the union. "I accept my suspension under the Joint Drug Program and I will try to move on with my life. I am deeply sorry for my mistake and I apologize to my teammates, to the San Francisco Giants organization and to the fans for letting them down."
Cabrera is batting .346 with 11 home runs and 60 RBIs in his first season with San Francisco.
"Ultimately, it was just a bad decision," catcher Buster Posey said.
Flashing bright orange spikes, Cabrera singled and hit a two-run homer last month in the NL's 8-0 All-Star win, which secured home-field advantage for the World Series.
He will miss the final 45 games of the regular season and serve the remainder of the suspension at the start of next season or during the postseason, depending on whether the Giants make the playoffs and how far they advance.
"We were extremely disappointed," the Giants said. "We fully support Major League Baseball's policy and its efforts to eliminate performance enhancing drugs from our game."
If the Giants wanted him to become active in the middle of a playoff series, they would have to play a man short from the start of the series until the suspension ends because rosters can't be altered midseries.
"It happened, and now we move on," right fielder Hunter Pence said. "I know the program and I know they test us, and if we test positive, we get a suspension. That's what happened. And now we play with what we've got."
It was not immediately known whether Cabrera's positive test occurred before the All-Star Game. The union initially filed a grievance, which would have caused the case to go before an arbitrator, but then dropped it, a person familiar with the process said. The person spoke on condition of anonymity because that detail was not announced.
Manager Bruce Bochy broke the news to his team in a meeting about 90 minutes before the start of a 6-4 loss to the Washington Nationals.
"Melky, he was hurt by it," Bochy said. "It's obvious he was disappointed."
Cabrera told CSN Bay Area on July 27 that he had been tested for performance-enhancing drugs the previous week, although it's unknown whether the test he referenced resulted in the positive test.
Drug-testing labs check urine for its ratio of testosterone to epitestosterone, which usually is 1 to 1 in adult males. If the lab notices any abnormality, it conducts an isotope ratio mass spectrometry (IRMS) test to determine whether the testosterone is exogenous, or came from outside the body.
Cabrera will not be permitted to work out with the Giants at any point during his suspension. Under the terms of Major League Baseball's drug policy, he can work out at the Giants' minor league complex but can't play in any minor league games.
Cabrera became the second Giants player to receive a drug suspension this season. Reliever Guillermo Mota was penalized for 100 games in May, becoming just the third major league player disciplined twice for positive drug tests. Mota is eligible to return Aug. 28, barring rainouts, and began a minor league rehabilitation assignment Tuesday with the Giants' rookie team in Arizona.
Robinson Cano, Cabrera's former teammate on the Yankees, was "100 percent surprised" by the news.
"It's really sad. He's having a great year," Cano said. "But, I'm his friend and I'm gonna be there for him."
There have been four suspensions in the major league drug program this year, with Philadelphia infielder Freddy Galvis and free-agent outfielder Marlon Byrd also suspended 50 games apiece. There have been 70 suspensions under the minor league drug program.
Yankees slugger Alex Rodriguez stood behind his former teammate.
"From my experience, I saw where he made a statement; that is always a good first step and sometimes the hardest," said Rodriguez, who admitted in 2009 to having taken performance-enhancing drugs. "I think he has an opportunity, being a young player. With that said, it is also going to be a challenge. I hope that he takes the bull by the horns and does some great things. I'm a believer and a friend. In times like this, I will definitely not turn my back and I'm here to support him."
Cabrera, 28, who became a marketing phenomenon with nicknames such as "Melk Man," "Got Melk?" and "Melky Way," produced a 51-hit month in May. Cabrera batted .429 in May with three homers, five triples, seven doubles and 17 RBIs. He hit safely in 25 of 29 games. The 51 hits matched Randy Winn for most hits in a month since the club came to San Francisco in 1958.
Cabrera also set the San Francisco record for most hits in May, passing Hall of Famer Willie Mays' 49 from 1958.
Cabrera came to the Giants in a trade with Kansas City last November that sent left-hander Jonathan Sanchez to the Royals. Cabrera -- who signed a $6 million, one-year deal to avoid salary arbitration -- batted .305 with 44 doubles, 18 homers and 87 RBIs last season.
He is a big reason San Francisco began play Wednesday tied with the Dodgers atop the NL West. Cabrera had been listed in the original lineup Wednesday, batting third and playing left field. Gregor Blanco replaced Cabrera. Bochy said he wrote that lineup before notice of the suspension.
"We are a team. We're trying to make the playoffs," Pablo Sandoval said. "We're going to fight."
San Francisco said it will not make a roster move until Thursday's off day before opening a weekend series at San Diego. The clubhouse was closed before the game when the news of Cabrera's suspension broke.
San Francisco optioned reliever Dan Otero to Triple-A Fresno after Wednesday's game and is expected to call up two hitters Friday in San Diego. Bochy and general manager Brian Sabean also plan to discuss who might be available outside the organization.
"It's a big loss to any team," shortstop Brandon Crawford said. "He was having an MVP-type season."
Information from ESPN.com's Jayson Stark, ESPNNewYork.com's Mike Mazzeo and The Associated Press was used in this report.