We show that a switched system generated by a pair of globally asymptotically stable nonlinear vector fields, which span a third-order nilpotent Lie algebra, is globally asymptotically stable under arbitrary switching. This generalizes a known fact for switched linear systems and provides a partial solution to the open problem posed in . To prove the result, we consider an optimal control problem which consists of finding the “most unstable” trajectory for an associated control system. We use the Agrachev-Gamkrelidze secondorder maximum principle to show that there always exists an optimal control that is piecewise constant with no more than four switches. This property is obtained as a special case of a reachability result by piecewise constant controls that is of independent interest. By construction, our criterion also holds for the more general case of differential inclusions.