The present invention provides a nitrogen-containing heterocyclic compound represented by the formula (I) (wherein, A-B represents any one of the formula (II): C=N, the formula (III): CH-NR9 and the formula (IV): N-C(=Y) R1, R2, R3 and R4 independently represent hydrogen atom, a halogen atom, a C1-20 alkyl group or the like R5, R6, R7 and R8 independently represent hydrogen atom, a halogen atom, a C1-20 alkyl group or the like X represents a halogen atom or the like and n represents an integer of 0 to 4 in the formula (III), R9 represents hydrogen atom, a C1-20 alkyl group or the like in the formula (IV), Y represents oxygen atom or sulfur atom.) and the salt thereof. The present invention also provides a fungicide for agricultural and horticultural use containing at least one of the said nitrogen-containing heterocyclic compound or the salt thereof as an active ingredient.