This article presents an analytical method based on solid-phase extraction (SPE) and gas chromatography coupled with mass spectrometry for the simultaneous determination of the most frequently used acidic pharmaceutical residues, ibuprofen, diclofenac, naproxen and ketoprofen (KFN), and phenolic endocrine disruptors, bisphenol (BPA), triclosan (TCS), nonylphenol, nonylphenol monoethoxylate and nonylphenol diethoxylate, in wastewater and sewage sludge samples. In the first phase of the study, each compound has been characterized individually and afterwards in mixture as a trimethylsilyl derivative in order to identify the characteristic ions (m/z ratio) constituting the mass spectrum and to choose the ions for quantification and confirmation. Subsequently, derivatization was evaluated by testing different variables such as the volume of the derivatization solvent bis(trimethylsilyl)trifluoroacetamide and the effect of each catalyst, pyridine and 1% trimethyl chlorosilane, in the derivatized solution. For the analysis of wastewater samples, two commercial SPE cartridges, C18 and Oasis HLB, were compared for their extraction efficiency of the target compounds. The key parameter of extraction procedure included the effect of pH (2.5, 5.3 and 7) of the loading solution. For solid samples, parameters such as the extracted biomass, the volume of the extraction organic solvent and the effect of matrix interferences in chromatographic analysis were evaluated. By using C18 cartridges as purification procedure and ultrasound sonication, satisfactory mean relative recoveries with BPA-d16 and meclofenamic acid as surrogates were obtained ranging from 91% to 117% for wastewater and 84% to 107% for sewage sludge samples. Nine-point calibration of the standard mixture was performed by linear regression analysis with a correlation coefficient >0.99 for all the tested compounds. Limits of detection for the developed methods were established between 0.3 (KFN) and 14.8 (BPA) ng L(-1), and 15.0 (TCS) and 32.9 (BPA) ng g(-1) for wastewater and sewage sludge, respectively. Application to real samples of the wastewater treatment plant in Athens, the capital of Greece, demonstrated the presence of all tested compounds in most of the samples.