A correction procedure is proposed to account for the effect of secondary X-ray fluorescence near grain boundaries in electron microprobe analysis. The procedure is based on the Monte Carlo simulation method, which is used to calculate the X-ray spectrum emitted by the mineral couple (i.e., the mineral of interest with the neighboring mineral). The contribution of secondary fluorescence from the neighboring mineral, which appears in the simulated spectrum in a natural way, is then subtracted from the measured k-ratio and thereafter conventional matrix corrections are applied. The Monte Carlo simulation algorithm used is largely based on the general-purpose simulation package PENELOPE. In order to assess the reliability of this code, simulated "apparent" element profiles are compared with electron microprobe measurements found in the literature, in which the effect of secondary fluorescence was characterized and the reliability of the different assumptions underlying the proposed procedure is discussed. Finally, the procedure is used to assess data from the olivine-clinopyroxene thermobarometer in a spinel lherzolite xenolith. The application of the secondary fluorescence correction leads to: (1) higher systematic pressure estimations than those obtained from uncorrected data, with lower uncertainties: and (2) a better agreement between the olivine-clinopyroxene temperature estimations and those estimated using the two-pyroxene thermometer. Estimated P-T conditions indicate a decompressional path with a slight decrease in temperature from core to crystal rim. However, if the effect of secondary fluorescence is not taken into account, an apparent heating event is observed.