Diazomethane is the chemical compound CH2N2, discovered by German chemist Hans von Pechmann in 1894. It is the simplest diazo compound. In the pure form at room temperature, it is an extremely sensitive explosive yellow gas; thus, it is almost universally used as a solution in diethyl ether. The compound is a popular methylating agent in the laboratory, but it is too hazardous to be employed on an industrial scale without special precautions. Use of diazomethane has been significantly reduced by the introduction of the safer and equivalent reagent trimethylsilyldiazomethane.
For safety and convenience diazomethane is always prepared as needed as a solution in ether and used as such. It converts carboxylic acids to methyl esters and phenols into their methylethers. The reaction is thought to proceed via proton transfer from carboxylic acid to diazomethane to give methyldiazonium cation, which reacts with the carboxylate ion to give the methyl ester and nitrogen gas. Labeling studies indicate that the initial proton transfer is faster than the methyl transfer step. Since proton transfer is required for the reaction to proceed, this reaction is selective for the more acidic carboxylic acids (pKa ~ 5) and phenols (pKa ~ 10) over aliphatic alcohols (pKa ~ 15).