Abstract: We estimate a workhorse DSGE model with an occasionally binding borrowing constraint. First, we propose a new specification of the occasionally binding constraint, where the transition between the unconstrained and constrained states is a stochastic function of the leverage level and the constraint multiplier. This specification maps into an endogenous regime-switching model. Second, we develop a general perturbation method for the solution of such a model. Third, we estimate the model with Bayesian methods to fit Mexico's business cycle and financial crisis history since 1981. The estimated model fits the data well, identifying three crisis episodes of varying duration and intensity: the Debt Crisis in the early-1980s, the Peso Crisis in the mid-1990s, and the Global Financial Crisis in the late-2000s. The crisis episodes generated by the estimated model display sluggish and long-lasting build-up and stagnation phases driven by plausible combinations of shocks. Different sets of shocks explain different variables over the business cycle and the three historical episodes of sudden stops identified.