Silicon Valley's tech giants tried to stop President Donald Trump from pulling the US out of the Paris climate accord.

It didn't work.

On Thursday, Trump said the US was dropping out of the agreement to curb global warming despite pleas to remain from Apple, Facebook and Google, as well as Elon Musk, founder of Tesla and SpaceX. Musk also threatened to leave several of the president's advisory councils, a pledge he made good on.

The US joined the Paris agreement in 2015. Nearly 200 countries are part of the accord and have agreed to fight global warming by reducing carbon emissions. Scientists anticipate climate change could push the Earth to dangerous temperatures much sooner if the US retreats from the pledge because the country burns so much energy.

Trump, however, sees the agreement as unfair to the US, and says it will cost the country jobs.

"In order to fulfill my solemn duty to protect America and its citizens, the United States will withdraw from the Paris climate accord, but begin negotiations to re-enter either the Paris accord or an entirely new transaction on terms that are fair to the United States," Trump said from the White House's Rose Garden on Thursday.

The decision came despite a full-court press by tech giants, which urged Trump to keep the US in the pact. The group included Musk, a Silicon Valley magnate who is in the president's inner circle and had argued he could use his position on economic advisory councils to influence the president.

On Wednesday, Musk said he did "all I can to advise" the president and threatened to leave Trump's advisory councils if the US left the agreement. After the announcement, Musk did just that.

Am departing presidential councils. Climate change is real. Leaving Paris is not good for America or the world.

Apple CEO Tim Cook personally called the White House on Tuesday to urge Trump to stay in the agreement, according to a company-wide email he sent Thursday. He added that Apple's commitment to protecting the environment was unchanged.

"Climate change is real and we all share a responsibility to fight it," Cook wrote."I want to reassure you that today's developments will have no impact on Apple's efforts to protect the environment."

The CEOs of Google, Facebook, Microsoft, HP and Intel also asked Trump in a letter to stay in the agreement. They argued that innovating clean technology would create more jobs, while protecting the country from climate change's devastating effects in the future.

"As other countries invest in advanced technologies and move forward with the Paris Agreement, we believe the United States can best exercise global leadership and advance US interests by remaining a full partner in this vital global effort," the letter reads.

The US joined the climate deal under former President Barack Obama, who on Thursday sided with tech leaders, citing the innovation spurred by green technology.

"The Paris Agreement opened the floodgates for businesses, scientists, and engineers to unleash high-tech, low-carbon investment and innovation on an unprecedented scale," Obama said in a statement after Trump's decision.

Amazon released a statement Thursday, saying it would still abide by the Paris climate agreement's rules.

"We believe that robust clean energy and climate policies can support American competitiveness, innovation and job growth," the retail giant said.

Microsoft's president and chief legal officer Brad Smith said the company had been actively working to convince the Trump administration not to leave the Paris Agreement. Microsoft had multiple meetings with senior officials in the State Department and the White House over the climate change accord, Smith said.

Facebook CEO Mark Zuckerberg said in a post a on the social network that withdrawing from the Paris agreement is "bad for the environment, bad for the economy, and it puts our children's future at risk." He added that Facebook has committed that "every new data center we build will be powered by 100% renewable energy."

Uber also weighed in on Trump's decision. "Today's announcement from President Trump that the United States will not honor the agreement is a huge disappointment," wrote Andrew Salzberg, Uber's head of transportation policy and research, in a blog post. "At Uber, we also believe that fighting climate change opens up new opportunities for American innovation and ingenuity to tackle the world's biggest problems."

The withdrawal will take four years to completely exit, and concludes in November 2020, when Trump is up for re-election.

CNET's Shara Tibken contributed to this report.

Multiple updates on June 1: To include statements from former President Obama, Amazon, ElonMusk, Microsoft, Facebook and Uber. Adds Apple email and Iger resignation from council.