TOKYO — A Japanese spacecraft left a distant asteroid on Wednesday, starting its yearlong journey home after successfully completing its mission to gather soil samples and data that could provide clues to the origins of the solar system, the country’s space agency said.

The Japan Aerospace Exploration Agency said the Hayabusa2 spacecraft left its orbit around the asteroid Ryugu, about 180 million miles from Earth.

Hayabusa2 staff at the command center stood up and cheered when JAXA project manager Yuichi Tsuda confirmed the departure.

The spacecraft captured and transmitted to Earth some of its final images of Ryugu, or “Dragon Palace,” named after a sea-bottom castle in a Japanese folk tale, as it slowly began moving away, JAXA said. Hayabusa2 will continue its “farewell filming” of the asteroid for a few more days.

Hayabusa2 will adjust its position about Nov. 18 after retreating 40 miles from the asteroid and out of its the gravitational pull. After that, Ryugu will be out of its sight.

“It’s sad to say goodbye to Ryugu,” Tsuda said at a briefing Tuesday. “Literally it has been at the center of our lives over the past 1½ years.”

The spacecraft will then ignite its main thrusters in early December to propel it back to Earth.

“We expect Hayabusa2 will bring us new scientific insights,” Tsuda said. “Not only the data, but tangible samples will be in our hands.”

Hayabusa2 touched down on the asteroid twice, despite its extremely rocky surface and successfully collected data and samples during its 1½-year mission since arriving there in June 2018.

In the first touchdown in February, it collected surface dust samples. In July, it collected underground samples from the asteroid for the first time in space history after landing in a crater that it had earlier created by blasting the asteroid’s surface.

Scientists said that there were traces of carbon and organic matter in the asteroid soil samples. “They will allow us to explore how carbon, organic matter and water are scattered around in the solar system, why they exist on Ryugu, how they are related to the Earth and its lives,” Tsuda said.

Hayabusa2 is expected to reach Earth in late 2020 and drop a capsule containing the precious samples in the Australian desert. Tsuda said landing the capsule at the targeted spot will be a challenge requiring precision controls. Details are still being negotiated with the Australian government, he said.

The spacecraft will only drop the capsule and then return to space for another possible mission.

It took the spacecraft 3½ years to arrive at the asteroid, but the journey home is much shorter thanks to the current locations of Ryugu and Earth.

JAXA scientists believe the underground samples contain valuable data unaffected by space radiation and other environmental factors that could tell more about the origin of the solar system 4.6 billion years ago.

Asteroids, which orbit the sun but are much smaller than planets, are among the oldest objects in the solar system and may help explain how Earth evolved. Hayabusa2 scientists also said they believe the samples contain carbon and organic matter and hope they can explain how they are related to Earth.