Opioids are the drugs most commonly detected in overdose deaths and the second most consumed worldwide. An analytical methodology has been optimized and fully validated for the determination of codeine, morphine, 6-acetylmorphine, 6-acetylcodeine, oxycodone, oxymorphone and fentanyl in whole blood and pericardial fluid. The internal standards used were codeine-d3, morphine-d3, 6-acetylmorphine-d3 and fentanyl-d5. Before solid-phase extraction, volumes of 250μL of blood and pericardial fluid were subjected to a protein precipitation (with 750μL of ice-cold acetonitrile) and a microwave-induced oximation was performed using a solution of 1% aqueous hydroxylamine hydrochloride in phosphate-buffered saline (1:2, v/v). Finally, the dried extracts were further derivatized with a solution of n-methyl-n-(trimethylsilyl) trifluoroacetamide+5% trimethylchlorosilane under microwave irradiation. The chromatographic analysis was carried out using gas chromatography-mass spectrometry operating in electron impact and selected ion monitoring mode. For all analytes, the method was linear between 5 and 1,000ng/mL with determination coefficients (r2) >0.99. Depending on the analyte and matrix, the limit of detection varies between 3 and 4ng/mL. Intra- and intermediate precision (<20%) and bias (±20%) were acceptable for all analytes in both matrices. The stability of the substances in the studied matrices was guaranteed, at least, 24h in the autosampler, 4h at room temperature and 30days after three freeze/thaw cycles. This methodology was applied to real samples from the Laboratory of Chemistry and Forensic Toxicology, Centre Branch, of the National Institute of Legal Medicine and Forensic Sciences, Portugal.