Many types of bacteria can survive under stress by switching stochastically between two different phenotypes: the "normals" who multiply fast, but are vulnerable to stress, and the "persisters" who hardly multiply, but are resilient to stress. Previous theoretical studies of such bacterial populations have focused on the fitness: the asymptotic rate of unbounded growth of the population. Yet for an isolated population of established (and not very large) size, a more relevant measure may be the population extinction risk due to the interplay of adverse extrinsic variations and intrinsic noise of birth, death and switching processes. Applying a WKB approximation to the pertinent master equation of such a two-population system, we quantify the extinction risk, and find the most likely path to extinction under both favorable and adverse conditions. Analytical results are obtained both in the biologically relevant regime when the switching is rare compared with the birth and death processes, and in the opposite regime of frequent switching. We show that rare switches are most beneficial in reducing the extinction risk.