The 23-year-old said recording Writing’s On The Wall for the film, which stars Daniel Craig as Bond, was “one of the highlights of my career”.
The song - co-written by Jimmy Napes, who worked with Smith on his number one hits Stay With Me and La La La - will be unveiled on September 25 but can be pre-ordered from midnight.
The In The Lonely Hour star revealed he recorded the track back in January but has been sworn to secrecy.
Just last week, Smith denied he was working on the project to BBC Radio 2’s Jo Whiley.
On Monday he teased fans by posting a picture on Twitter of a ring on his finger, featuring the symbol of an octopus with blade-like tentacles, the symbol of the Spectre organisation from the 007 universe.
He has now tweeted: “This is one of the highlights of my career. I am honoured to finally announce that I will be singing the next Bond theme song.
“I am so excited to be a part of this iconic British legacy and join an incredible line up of some of my biggest musical inspirations.
“I hope you all enjoy the song as much as I enjoyed making it.”
It is the first James Bond theme recorded by a British male solo artist since 1965, when Sir Tom Jones released Thunderball.
Smith told Radio 1’s Nick Grimshaw: “I’m so relieved to actually talk about this, this has been a top secret mission of my own.”
He added: “I got called into the office with (producer) Barbara Broccoli and (director) Sam Mendes and they gave me the script, I read the script... they said ‘have a go at the song’.
“It’s the quickest I’ve ever written a song - it took 20 minutes... and they loved it!”
Spectre, thought to be Craig’s final outing as Bond and starring Christoph Waltz as the lead villain, will have it’s world premiere in London on October 26.
It will be simultaneously released in cinemas throughout the UK on the same day and tickets are already on sale.
British star Adele wrote and performed the last Bond theme, Skyfall, which went on to win a string of accolades, including an Oscar, a Grammy and a Golden Globe.
It entered the UK charts at number 4, and rose to the number two spot after 14 days, tying with Duran Duran’s A View To A Kill as the highest-charting Bond theme ever.
Smith has been the bookmakers’ favourite to sing the theme for some time, but there was a lot of disappointment expressed on social media at the announcement.
Many Bond fans felt he was not the right choice.
Gareth Armstrong wrote on Twitter: “Spectre had better be amazing now, I’m not sitting through a Sam Smith song for a mediocre film.”
Lloyd Armstrong wrote: “So how late will I have to be to see #SPECTRE but miss the Sam Smith theme song?”
And Darryll Preedy tweeted: “Ugh, so Sam smith is singing the James Bond song. Hopefully it won’t be too dreadful..”
But others were more positive.
Peter Richmond declared: “As a true bond fan I am personally delighted Sam Smith has recorded the theme for #spectre he is British and has a great voice.”