No 10 had said Rishi Sunak was too busy preparing for the 17 November budget to attend the event which opens on Sunday.
But this had been widely criticised by climate campaigners, opposition parties and climate adviser Alok Sharma.
Mr Sunak tweeted that there would be "no long-term prosperity without action on climate change" or energy security without investing in renewables.
"That is why I will attend @COP27P next week: to deliver on Glasgow's legacy of building a secure and sustainable future."
On Tuesday, former prime minister Boris Johnson said he would attend COP27 in Sharm El Sheikh.
The UK hosted last year's COP (Conference Of The Parties) in Glasgow and it was chaired by Mr Sharma.
Green MP Caroline Lucas welcomed what she called a "screeching U-turn" after "an embarrassing mis-step on the world stage".
"Let this be a lesson to him - climate leadership matters," she added.
Labour leader Sir Keir Starmer accused the prime minister of acting "in the name of political management" rather than the national interest.
"Caving in to criticism is not leadership. Real leadership is seizing your seat at the table. For UK jobs. For clean energy. For our environment," he tweeted.
Liberal Democrat climate change spokesperson Wera Hobhouse said: "This whole debacle has shown the environment is simply not a priority for Rishi Sunak. He's only going after being embarrassed by Boris Johnson's attendance."
Mr Sharma, who had said he was "disappointed" Mr Sunak would not be attending, tweeted that he was "delighted" the prime minister would now be going.
Many world leaders including US President Joe Biden and France's Emmanuel Macron are due to attend the UN event.
Mr Sunak's predecessor Liz Truss had been set to go and Scotland's First Minister Nicola Sturgeon will also be there.
King Charles - a long-time champion of environmental causes - will not be going, despite speaking at COP26 in Glasgow.
Downing Street said Liz Truss's government had agreed with Buckingham Palace that it was not the "right occasion" for the King to attend - and this advice had not changed.
The annual climate summits are designed to help governments agree measures to limit rises in global temperatures.
This year's conference takes place from 6 to 18 November, finishing the day after Chancellor Jeremy Hunt is due to set out the government's tax and spending plans.
On Tuesday, Mr Sunak's official spokesman said "significant progress" was being made on the autumn statement.