Cocaine is primarily metabolized in the liver through hydrolysis and oxidation, producing metabolites such as benzoylecgonine and ecgonine methyl ester. These metabolites are excreted in the urine and can be detected for several days after use. Understanding the metabolism and elimination of cocaine is crucial for toxicological analysis and forensic investigations.