We develop an N-regime Markov-switching model in which the latent state variable driving the regime switching is endogenously determined with the model disturbance term. The models structure captures a wide variety of patterns of endogeneity and yields a simple test of the null hypothesis of exogenous switching. We derive an iterative filter that generates objects of interest, including the model likelihood function and estimated regime probabilities. Using simulation experiments, we demonstrate that the maximum likelihood estimator performs well in finite samples and that a likelihood ratio test of exogenous switching has good size and power properties. We provide results from two applications of the endogenous switching model: a three-state model of US business cycle dynamics and a three-state volatility model of US equity returns. In both cases, we find statistically significant evidence in favor of endogenous switching.