Ramirez, who was suspended 50 games in 2009 for violating the league's drug policy, was recently informed by Major League Baseball that there was an issue relating to the policy.
"Rather than continue with the process under the program, Ramirez has informed MLB that he is retiring as an active player," the league said in a statement. "If Ramirez seeks reinstatement in the future, the process under the drug program will be completed."
The New York Times reported on their website that Ramirez tested positive during spring training with the Tampa Bay Rays, his most recent club, and would have faced a 100-game ban for a second offence if he had not retired.
A spokesman for Major League Baseball declined to comment.
The Rays, who signed Ramirez this year, said they were informed of the slugger's decision by the league.
"We are obviously surprised and disappointed by the news. We will have no further comment on this matter, and our fans and organization will carry on," the Rays said in a statement.
The 38-year-old Ramirez, who was 1-for-17 with the Rays this season, made his name with the Cleveland Indians and Boston and had spells with the Los Angeles Dodgers and the Chicago White Sox toward the end of his career.
Ramirez, born in the Dominican Republic, missed Tampa Bay's game at Chicago Thursday to attend to what the team said was a family matter.
With his flowing locks, big-hitting style and lively personality, Ramirez was a popular figure among fans of his teams throughout his career.
But he will also be remembered for his positive test, one of a series of doping-related stories that have tarnished the reputation of baseball, known as America's national pastime.
Ramirez's retirement came at the end of a week where Barry Bonds, the league's all-time home run record holder, was facing perjury charges stemming from an appearance before a U.S. grand jury in 2003 when he testified that he did not use steroids or growth hormones.
Ramirez was selected by Cleveland in the first round of the 1991 draft and retires with a .312 batting average, 555 home runs and 1,831 RBIs.
(Reporting by Simon Evans in Miami)