Just a week before he was scheduled to give his end of year speech, 18-year-old New Zealand student Jake Bailey was diagnosed with a potentially terminal form of cancer and given just three weeks to live.

But defying doctors' predictions that he'd never make it to his high school's prize-giving speech, the young head boy delivered an inspirational 20-minute speech to a breathless audience.

From his wheelchair, the pale but remarkably strong-voiced Bailey urged his peers: "None of us get out of life alive. So be gallant, be great, be gracious and be grateful for the opportunities you have."

"Whilst we can't be the best at everything or, at some times, anything, what we can have is moral strength. I wrote this before I knew I had cancer, and now I've put a whole new spin on it. Moral strength is about making a conscious decision to be someone who doesn't give up when it may be easy to."

The video has gone viral since being posted last Thursday, with nearly a quarter of a million views as of Monday evening.