The minimal work principle states that work done on a thermally isolated equilibrium system is minimal for adiabatically slow (reversible) realization of a given process. This principle, one of the formulations of the second law, is studied here for finite (possibly large) quantum systems interacting with macroscopic sources of work. It is shown to be valid as long as the adiabatic energy levels do not cross. If level crossing does occur, counter examples are discussed, showing that the minimal work principle can be violated and that optimal processes are neither adiabatically slow nor reversible. The results are corroborated by an exactly solvable model.