Composting is a common treatment for the high amounts of sewage sludge produced in wastewater treatment plants, and the product is used in agriculture. Composting reduces the levels of biodegradable organic pollutants, although other compounds present in wastewater and not eliminated previously by conventional physical–chemical and chemical treatments, such as polychorodibenzo-p-dioxins/furans (PCDD/Fs) and polychlorinated biphenyls (PCBs), have been found in the final compost at higher levels than those observed in the initial sludge. Their formation was studied during composting under unfavorable aeration conditions and paying attention to different stages of the process. Experiments were carried out in small vessels inside a controlled oven for three types of sewage sludge. Pentachlorophenol was previously added as a dioxin precursor. A clear formation of PCDD/Fs was found, especially during the maturation stage for two experiments. Mainly octachlorodibenzo-p-dioxin (OCDD) and 1234678-heptachlorodibenzo-p-dioxin (1234678-HpCDD) to a lesser extent were formed. OCDD levels in the final samples were around 10 times higher than those of the initial mixture after removing the concentration effect. No clear formation nor degradation of PCBs was observed. The toxicity values due to PCDD/Fs and PCBs found in the initial mixtures were 1.20–2.46 ng WHO-TEQ/kg, and those from the final samples were 2.30–7.86 ng WHO-TEQ/kg. Although the toxicity values are below the most restrictive limits found in Europe in this case, toxicity could increase considerably with the presence and concentration of other precursors. Compost from sewage sludge is an ecological product, but the operating conditions must be controlled to avoid PCDD/F formation and facilitate degradation of persistent organic pollutants.