SpaceX's latest attempt to land a rocket upright on a platform in the Pacific Ocean failed in a spectacular fashion on Sunday.

The unmanned mission, powered by a SpaceX rocket, accomplished its primary goal of carrying a satellite into low orbit. But its secondary goal -- to land the rocket upright on a floating platform called a droneship -- ended in a fiery explosion.

SpaceX CEO Elon Musk posted a video on Sunday night of the botched landing on Instagram, showing the rocket setting down softly but then toppling over and exploding on impact.

The company, which initially said it thought the rocket experienced a "hard landing," explained that one of the legs failed to latch on the landing platform.

"Root cause may have been ice buildup due to condensation from heavy fog at liftoff," Musk said in his post.

Falcon lands on droneship, but the lockout collet doesn't latch on one the four legs, causing it to tip over post landing. Root cause may have been ice buildup due to condensation from heavy fog at liftoff. A video posted by Elon Musk (@elonmusk) on Jan 17, 2016 at 7:07pm PST

Sunday's launch was the fourth attempt by Elon Musk's SpaceX to safely land a rocket at sea.

Rockets are the portion of spacecrafts that provide the boost for liftoff, but they're typically discarded after launch. Companies like SpaceX that make rockets are working to perfect landing the rocket safely so they can be reused.

Rockets are expensive. SpaceX rockets cost between $60 million and $90 million. So the ability to reuse them would significantly reduce the cost of space travel.

Related: A short history of SpaceX's attempted rocket landings

After three previous failed attempts to land a rocket upright on a platform at sea, SpaceX successfully landed one of its Falcon 9 rockets on land after a launch from Florida's Cape Canaveral Air Force Station in December.

The successful landing came shortly after Blue Origin -- led by Amazon (AMZN) founder Jeff Bezos -- also landed a rocket upright on land.

After Sunday's launch, Bezos congratulated the company on Twitter. The two billionaire CEOs have recently traded barbs on social media about their rockets.

Impressive launch and @SpaceX will soon make Falcon 9 landings routine -- so good for space! Kudos SpaceX! — Jeff Bezos (@JeffBezos) January 17, 2016

SpaceX conducted Sunday's launch, which was made from Vandenberg Air Force Base in California, for NASA. The satellite that was launched into space, named Jason-3, will measure ocean levels on the Earth's surface.

"Jason-3 data will be used for monitoring global sea level rise, researching human impacts on oceans, aiding prediction of hurricane intensity, and operational marine navigation," NASA said.

NASA partnered with several other organizations on the project, including two European space agencies.

Out at sea for tomorrow's launch and landing attempt pic.twitter.com/9LMsj6qryI — SpaceX (@SpaceX) January 17, 2016

This was the second successful mission SpaceX has carried out since disaster struck in July. That's when SpaceX's rocket exploded shortly after launch, destroying an unmanned spacecraft carrying supplies to the International Space Station.

It returned to space missions in December when the company successfully carried satellites into low orbit in a mission for Orbcomm (ORBC).