This study investigated the diesel and COD removal from oily wastewater by electrocoagulation. Experiments were conducted in a 2-l reactor using aluminum and iron electrodes. Effects of different parameters including pH (3-11), time (10-60 min), voltage (4.5-10.5 V), supporting electrolyte (NaCl concentration), electrode material and initial diesel concentration (3500-11,000 mg/L) were studied in order to evaluate the efficiency of electrocoagulation. Furthermore, the consumption of energy and the amount of sludge produced by this method were evaluated. The highest removal efficiency (COD removal of 99.1 ± 0.2 % and diesel removal of 98.8 ± 0.2 %) was observed under the following conditions: pH 7, 40 min, 10.5 V, NaCl concentration of 0.5 g/ L, diesel concentration of 3500 mg/L. The consumption of energy was estimated to be 6.47 kWh/m 3 , and the amount of sludge generated was 1995 mg/L. The results demonstrated that the electrocoagulation is a feasible technique for treatment of heavily contaminated petroleum refinery wastewater.