This paper develops a testable theory of a firm´s hedging decision with endogenous leverage. Starting from a joint irrelevance theorem, we extend the traditional approach to optimal capital structure, which trades off the market values of financial distress costs and corporate taxes, by giving management the opportunity to hedge the firm´s output price risk by means of a forward contract. It is shown that a unique optimal debt level exists for any given hedge ratio and that the optimal amount of outstanding debt is increased by an exogenous increase in the forward position, if and only if, the probability that the firm will go bankrupt is reduced. Moreover, we prove that, with the optimal capital structure, shareholder wealth is a strictly monotonically increasing function of the firm's hedge ratio, if the transaction costs of hedging are negligible. If, however, the benefits of corporate hedging are negated by substantial transaction costs, it emerges that those optimally levered firms will choose higher hedge ratios, which face more volatile operating cash flows and more convex deadweight claim payoff profiles. In contrast to previous models in the literature, our framework is based on less restrictive distributional assumptions and allows an analytical solution to the joint optimization problem that features empirically testable comparative statics. We suggest, in particular, that empirical research, which aims at explaining observable differences in firms´ hedge ratios, should test the explanatory power of a proxy variable for the convexity of financial distress cost functions on a cross-sectional basis. This proxy variable, which is intended to measure the vulnerability of firm value with respect to adverse changes in the firm's perceived bankruptcy risk, may be estimated by means of time-series regressions that make use of both credit default swap spread and stock price data.