We develop an analytically-tractable model integrating the dynamic theory of investment with dynamic optimal incentive contracting, thereby endogenizing financing constraints. Incentive contracting generates a history-dependent wedge between marginal and average q, and both vary over time as good (bad) performance relaxes (tightens) financing constraints. Financial slack, not cash flow, is the appropriate proxy for financing constraints. Investment decreases with firm-specific risk, and is positively correlated with past profits, past investment, and managerial compensation even with time-invariant investment opportunities. Optimal contracting involves deferred compensation; possible termination; and compensation that depends on exogenous observable persistent profitability shocks, effectively paying managers for luck.