I develop an analytically tractable model that integrates the risk-shifting problem between bondholders and shareholders with the moral hazard problem between shareholders and the manager. An optimal contract binds shareholders and manager, and this contract’s flexibility allows shareholders to relax the manager’s incentive constraint following a “good” profitability shock. Thus the optimal contract amplifies the upside and thereby increases shareholder appetite for risk shifting. Whereas some empirical studies find a positive relation between risk shifting and leverage, others find a negative relation. This model predicts a non-monotonic relation between risk shifting and leverage and can reconcile these contradictory empirical findings.