Japan's ruling Liberal Democratic Party (LDP) and its junior partner signed a coalition deal on Monday, paving the way for Sanae Takaichi to become the country's first woman premier.
The 11th-hour agreement with the Japan Innovation Party (JIP) came just a day before the lower house was due to vote on Takaichi's appointment as the fifth prime minister in as many years.
If she wins, she will take office the same day.
"I'm very much looking forward to working with you on efforts to make Japan's economy stronger and to reshape Japan as a country that can be responsible for future generations," Takaichi told the JIP's co-head Hirofumi Yoshimura as they signed the deal.
Yoshimura said he was convinced the parties were "on the same page about our passion to move Japan forward".
Takaichi, 64, seen as a China hawk and traditionalist from the right wing of the LDP, won the party leadership this month.
But her bid to become premier was derailed by the collapse of the LDP's coalition with the Komeito Party after 26 years.
Komeito said the LDP had failed to tighten party funding rules following a damaging slush fund scandal.
It was also unnerved by Takaichi's previous harsh rhetoric on China and her regular visits to a Tokyo shrine that honours Japan's war dead, including war criminals.
The clock was ticking for Takaichi to be appointed.
US President Donald Trump is due to visit at the end of the month on his way to the Asia-Pacific Economic Cooperation summit in South Korea.
Details of a trade deal between Washington and Tokyo remain unresolved, and Trump also wants Japan to stop Russian energy imports and boost defence spending.
The LDP's new coalition with JIP is still two seats shy of the lower house majority needed for Takaichi to be appointed.
But Takaichi is still likely to win since in a second-round run-off vote she only needs more support than the other candidate.
The announcement of a new coalition pushed the Nikkei 225 Index up more than three percent to a new record above 49,000 points.
Yutaka Miura, analyst at Mizuho Securities, said that investors were cheered by hopes of "proactive fiscal policies" by Takaichi. (AFP)