Pellagra is caused by niacin (vitamin B3) deficiency and patients with pellagra present with a characteristic rash. Isoniazid disrupts intracellular niacin synthesis and might induce niacin deficiency. In 2017, Malawi scaled up continuous isoniazid preventive treatment (IPT) for tuberculosis prevention among people living with HIV. In addition, an under-diversified diet based on subsistence maize, as is commonly the case in Malawi, is a risk factor for pellagra. We aimed to investigate whether large-scale isoniazid exposure in Malawi contributed to the cumulative risk for pellagra in a nutritionally vulnerable population. We did a matched case-control study to evaluate the association between daily, continuous isoniazid exposure and pellagra. We matched sequentially enrolled patients with pellagra each with four control participants by sex and age from referral dermatology centres in three IPT scale-up districts in Malawi (Lilongwe, Blantyre, and Zomba) to evaluate isoniazid as a risk for pellagra using multivariable conditional logistic regression. We established a community clinic referral system surrounding the dermatology clinic in each district to enhance case-finding and included all patients with pellagra, regardless of referral status. The primary outcome was dermatologist-diagnosed pellagra. We calculated the interval between isoniazid initiation and rash onset and assessed 30-day clinical outcomes after multi-B vitamin treatment containing 300 mg nicotinamide daily. Between Feb 5 and Aug 9, 2019, we enrolled 197 patients with pellagra and 781 matched controls. Isoniazid exposure was associated with an increased risk of pellagra (adjusted odds ratio 42·6 [95% CI 13·3-136·6]). Significant covariates included HIV infection, referral status, food insecurity, underweight, excess alcohol consumption, and, among women, lactation. The median time from isoniazid initiation to rash onset was shorter during the season of food scarcity (5 months [IQR 3-7]) compared with the harvest season (9 months [8-11]; hazard ratio 7·2 [95% CI 3·2-16·2], log-rank p<0·0001). Those with isoniazid-associated pellagra who discontinued isoniazid and adhered to multi-B vitamin treatment showed 30-day clinical improvement. Continuous IPT scale-up and the annual period of food scarcity both increased the risk of pellagra in Malawi. Use of shorter rifamycin-based regimens for tuberculosis prevention and food fortification in populations with undernutrition might reduce this risk. Niacin-containing multi-B vitamin co-administration with isoniazid as pellagra prevention is worth exploring further. This study was supported by the President's Emergency Plan for AIDS Relief through the US Centers for Disease Control and Prevention under project 7173.