Root-knot nematodes (RKNs; Meloidogyne spp.) are obligate endoparasites that infect many crops and cause severe yield losses. In this research, we studied the effect of Welsh onion, grown as a companion plant, on the resistance of cucumber plants to RKN infection and analyzed the most abundant components of Welsh onion root exudates. The results showed that, when grown with Welsh onion as a companion plant, cucumber roots had 77.0% fewer root knots and egg masses than the control cucumber roots. Welsh onion root exudates were collected and extracted with chloroform, ethyl ether, n-butanol and ethyl acetate. High concentrations of the extracts from the Welsh onion root exudates decreased the hatchability of RKN eggs. In particular, the inhibitory effect of the n-butanol extract was significant and the hatchability of RKN eggs did not exceed 10%. Gas chromatographic–mass spectrometric analysis revealed that the most abundant component in the n-butanol extract was 4-hydroxy-benzeneethanol. Treatment with 1.2 mM 4-hydroxy-benzeneethanol decreased egg hatchability to 40%, whereas treatment with 9.6 mM or a higher concentration of 4-hydroxy-benzeneethanol decreased egg hatchability to less than 10%. In addition, 1.2 mM or a higher concentration of 4-hydroxy-benzeneethanol decreased the activity of the second-stage juvenile (J2). Higher 4-hydroxy-benzeneethanol concentrations (9.8 and 19.2 mM) were lethal to RKNs to some extent, with death rates greater than 50% at 48 h of treatment. The present results suggest that cultivation with Welsh onion as a companion plant may represent an alternative to the application of synthetic nematicides, with fewer side effects. We confirmed that 4-hydroxy-benzeneethanol is a natural effective nematicide.