A teacher battling an aggressive cancer has received a touching tribute from his students, after they surprised him by going to his home and singing hymns under his window.

Ben Ellis has been teaching at Christ Presbyterian Academy (CPA) in Nashville since 2008, and was diagnosed with oesophageal cancer in December last year.

Last week, he and his family decided to discontinue his treatment, deciding "the time that would be needed for any type of treatment to be effective would almost certainly exceed the time that Ben has left".

Christ Presbyterian headmaster Nate Morrow said when the school found out about the decision, principal Parker Altman decided they would "go sing to Mr Ellis".

Leslie Ponder, a teacher at CPA, said the trip was a "spur-of-the-moment decision".

"This is one of the many things I love about CPA, they will stop 'education' for a bigger lesson — a lesson of life, of love, of compassion, of community," she wrote on Facebook.

"Today these students learned more than they would have in a classroom."

Mr Ellis described the singing by the 400 students — the entire student body — as "beautiful and unforgettable".

"I have never felt so weak but God is strong in me," he said.

Mr Ellis would often organise hymn sing-alongs with the students, Mr Morrow told Buzzfeed News.

"This is a man who loved us well and we want to go love him well," he said.

The video was shared by country singer Tim McGraw, who said he received the video from a friend.

It has since been viewed more than 21 million times.