President Pedro Castillo rushed back to Peru by car from a visit to Ecuador to avoid being impeached, after bad weather grounded his plane.
Peru is politically unstable and removes its presidents frequently.
Castillo risked violating the constitution -- and giving the opposition an excuse to go after him -- if he failed to arrive back in Peru by midnight Friday leading into Saturday.
That was the deadline set by Congress as it approved his visit to neighboring Ecuador, where Castillo met with President Guillermo Lasso in the city of Loja, which is 264 kilometers (160 miles) from the Peruvian border.
Castillo leads a minority government, and the legislature is actually controlled by opposition parties.
As bad weather prevented the presidential plane from taking off Friday evening, Castillo set off by car on a five-hour journey to cross the border in time.
He arrived at the Tumbes border crossing with an hour to spare, local news organizations reported.
Castillo, a leftist, has only been in power for nine months, and already Congress has voted twice to try to remove him.
These impeachment motions have become common in Peru and brought down presidents Pedro Pablo Kuczynski in 2018 and Martin Vízcarra in 2020.
Since December 2017, Peru's Congress has held no fewer than six impeachment votes.