We study the valuation of mortgage-backed securities when borrowers may have to refinance at premium rates because of their credit. The optimal refinancing strategy often results in prepayment being delayed significantly relative to traditional models. Furthermore, mortgage values can exceed par by much more than the cost of refinancing. Applying the model to an extensive sample of mortgage-backed security prices, we find that the implied credit spreads that match these prices closely parallel borrowers' actual spreads at the origination of the mortgage. These results suggest that models that incorporate borrower credit into the analysis may provide a promising alternative to the reduced-form prepayment models widely used in practice.