Heteroarylpiperidine and -piperazine derivatives of the formula (I) in which the symbols are each as defined in the description, and agrochemically active salts thereof, and use thereof for controlling phytopathogenic harmful fungi, and also processes for preparing compounds of the formula (I).