This article studies the estimation of state space models whose parameters are switching endogenously between two regimes, depending on whether an autoregressive latent factor crosses some threshold level. Endogeneity stems from the sustained impacts of transition innovations on the latent factor, absent from which our model reduces to one with exogenous Markov switching. Due to the exible form of state space representation, this class of models is vastly broad, including classical regression models and the popular dynamic stochastic general equilibrium (DSGE) models as special cases. We develop a computationally efficient filtering algorithm to estimate the nonlinear model. Calculations are greatly simplied by appropriate augmentation of the transition equation and exploiting the conditionally linear and Gaussian structure. The algorithm is shown to be accurate in approximating both the likelihood function and filtered state variables. We also apply the filter to estimate a small-scale DSGE model with threshold-type switching in monetary policy rule, and find apparent empirical evidence of endogeneity in the U.S. monetary policy shifts. Overall, our approach provides a greater scope for understanding the complex interaction between regime switching and measured economic behavior.