This paper presents a theory of optimal debt structure when the moral hazard problem is severe. The main idea is that the optimal debt contract delegates monitoring to a single senior lender and that seniority allows the monitoring senior lender to appropriate the full return from his monitoring activities. The theory explains (i) why debt contracts are prioritized, (ii) why short-term debt is senior to long-term debt, and (iii) why financial intermediaries usually hold short-term senior debt whereas long-term junior debt is widely held. Another implication of the theory is that covenant and maturity structures will be set to conform to the seniority structure.