This paper introduces Finite Elements with Switch Detection (FESD), a numerical discretization method for nonsmooth differential equations. We regard the Filippov convexification of these systems and a transformation into dynamic complementarity systems introduced by Stewart [44]. FESD is based on solving of nonlinear complementarity problems and able to automatically detect the nonsmooth events in time. If standard Runge-Kutta (RK) methods are naively applied to a nonsmooth ODE, the accuracy is at best of order one. In FESD, we let the integrator step-size to be a degree of freedom. Additional complementarity conditions, that we call cross complementarities, enable exact switch detection, hence FESD is able to recover the high order accuracy which the RK methods enjoy for smooth ODE. Additional conditions called step equilibration allow the step-size to change only when switches occur and thus avoid spurious degrees of freedom. Convergence results for the FESD method are derived, local uniqueness of the solution and convergence of numerical sensitivities are proven. The efficacy of FESD in demonstrated on several simulation and optimal control examples.