A Welfare-to-Work (WTW) program is a mix of government expenditures on “passive” (unemployment insurance, social assistance) and “active” (job search monitoring, training, wage taxes/subsidies) labor market policies targeted to the unemployed. This paper provides a dynamic principal-agent framework suitable for analyzing the optimal sequence and duration of the different WTW policies, and the dynamic pattern of payments along the unemployment spell and of taxes/subsidies upon re-employment. First, we show that the optimal program endogenously generates an absorbing policy of last resort (that we call “social assistance”) characterized by a constant lifetime payment and no active participation by the agent. Second, human capital depreciation is a necessary condition for policy transitions to be part of an optimal WTW program. Whenever training is not optimally provided, we show that the typical sequence of policies is quite simple: the program starts with standard unemployment insurance, then switches into monitored search and, finally, into social assistance. Only the presence of an optimal training activity may generate richer transition patterns. Third, the optimal benefits are generally decreasing or constant during unemployment, but they must increase after a successful spell of training. In a calibration exercise based on the U.S. labor market and on the evidence from several evaluation studies, we use our model to analyze quantitatively the features of the optimal WTW program for the U.S. economy. With respect to the existing U.S. system, the optimal WTW scheme delivers sizeable welfare gains, by providing more insurance to skilled workers and more incentives to unskilled workers.