Gifted Kids and the Rejection of External Motivation

Every once in a while, though, a student came along who was so disenchanted by the educational system, so convinced that it was irrelevant, that he did everything possible to declare his independence.
By the time they got to me, at age 15, it was almost too late.
What can we do in the early years to help kids stay engaged and motivated so they don’t reject the system and end up failing out of school?