Highly active antiretroviral therapy (HAART) causes a rapid increase of CD4 + T cells counts during the first 3–6 months of treatment and may enhance the development of opportunistic infections (OIs). However, the short- and long-term effects of HAART exposure on the development of incident OIs has not been extensively studied. This nationwide longitudinal study followed up a total of 26,258 people living with HIV/AIDS (PLWHA) to ascertain the short- and long-term effects of HAART on incident OIs. During 150,196 person-years of follow-up, 6,413 (24.4%) PLWHA had new onset of OIs. After adjusting for demographics, comorbidities, and AIDS status, PLWHA who received HAART were more likely to develop OIs than those who did not receive HAART. Considering the short- and long-term effects of HAART on the development of OIs, HAART was found to be a risk factor for developing OIs during the first 90 days of treatment, but a protective factor against OIs after 180 days of HAART use. The risk for the development of active OIs significantly decreased as the duration of HAART increased (P < 0.001). Our study suggests that HAART is a risk factor for developing OIs in the short term, but is a protective factor in the long term.