In a two-agent, two-good, private information, risk-sharing environment, conditions are described under which a collateralized debt contract is the optimal allocation within the set of all resource and incentive feasible allocations, even allowing for extraneous randomization. In a collateralized debt contract, the borrower usually pays a fixed amount of one good and none of the second good, but it the first good is insufficient, all of the first good and some of the second good are paid. The second good thus serves as collateral, and is essential in nontrivial contracts in order to satisfy incentive constraints. The critical conditions for optimality are that preferences are heterogeneous in a particular way, and that the absolute risk aversion of the borrower is nonincreasing. The amount of the collateral good available to the borrower can sharply constrain contracts in the sense that it imposes an upper limit on the compensation available to the lender in feasible contracts. The results suggest applications to a wide range of financial arrangements.