This study examines the role of gender of the head of household on the food security of small-scale subsistence farmers in urban and rural areas of South Africa, using the exogenous switching treatment-effects regression framework. Our results show that agriculture contributes to food security of female-headed more than male-headed households, especially in rural areas. We also observe that male-headed households are more food secure compared to female-headed households, and this is mainly driven by differences in off-farm labour participation. We further observe that the food security gap between male- and female-headed households is wider in rural than in urban areas, where rural male- and female-headed households are more likely to report chronic food insecurity, i.e., are more likely to experience hunger than their urban counterparts. Our results suggest that the current policy interest in promoting rural and urban agriculture is likely to increase food security in both male- and female-headed household, and reduce the gender gap.