We provide general conditions under which principal-agent problems admit mechanisms that are optimal for the principal. Our result covers as special cases those in which the agent has no private information – i.e., pure moral hazard – as well as those in which the agent’s only action is a participation decision – i.e., pure adverse selection. We allow multi-dimensional actions and signals, as well as both financial and non-financial rewards. Beyond measurability, we require no a priori restrictions on the space of mechanisms. Consequently, our optimal mechanisms are optimal among all measurable mechanisms. A key to obtaining our result is to permit randomized mechanisms. We also provide conditions under which randomization is unnecessary.