A new fast, sensitive, and environmentally friendly analytical method has been developed for the simultaneous determination of Ba, Be, Cd, Cr, Cu, Fe, Hg, Mn, Ni, Pb, and Zn in wastewater samples using inductively coupled plasma optical emission spectroscopy (ICP OES). A preconcentration step using a magnetic dispersive solid-phase extraction (MDSPE) technique with a new magnetic sorbent was performed. The new sorbent material was a carbon containing magnetic cobalt and nitrogen groups. This material was synthetized using controlled pyrolysis of a zeolitic imidazolate framework (i.e., ZIF-67). In order to optimize the experimental parameters that affect the MDSPE procedure, a multivariate optimization strategy, using Plackett–Burman and circumscribed central composite designs (CCD), was used. The method has been evaluated employing optimized experimental conditions (i.e., sample weight, 10 g; sample pH, 7.6; amount of sorbent, 10 mg; dispersive agent, vortex; complexing agent concentration, 0.5%; ionic concentration, 0%; eluent, HCl; eluent concentration, 0.5 M; eluent volume, 300 μL; elution time, 3 min and extraction time, 3 min) using external calibration. Limits of detection (LODs) in a range from 0.073 to 1.3 μg L−1 were obtained, and the repeatability was evaluated at two different levels, resulting in relative standard deviations below 8% for both levels (n = 5). An increase in the sensitivity was observed due to the high enrichment factors (i.e., 3.2 to 13) obtained compared with direct ICP OES analysis. The method was also validated through carrying out recovery studies that employed a real wastewater sample and through the analysis of a certified reference material (ERM®-CA713). The recovery values obtained with the real wastewater were between 94 and 108% and between 90 and 109% for the analysis of ERM®-CA713, showing negligible matrix effects.