The ballad, which was co-written by former 'American Idol' winner Kris Allen, will be played by Matthew alone on an empty theatre stage.
He told The Hollywood Reporter: "It was going to be just a big dance piece with me doing this big dance number. But they said, 'We want you to sing it and make it a big moment.' "
Dana Walden, 20th Century Fox Television chairman, agreed to allow the track to be put in the finale – which airs in the US on May 24 - only if it fitted the character.
'Glee' creator Ryan Murphy said: "It's about aspiration. It worked because we wanted to do a scene where Matt goes into a Broadway hall and sings something alone. Plus, Matt is such a great team player and he's done so much for different 'Glee' charities.
"We worked really hard to make it feel organic to the show."
Matt recently confirmed there would be a death at the end of the second season of 'Glee'.
He said: "Somebody's dying. Obviously I'm not going to tell you who it is, but it is no-one you would probably expect.
"The episode right before the finale is called 'Funeral'."
Fox plans a live 3D show of Glee this summer
‘Glee’ present Fleetwood Mac episode - VIDEO