Two days before Mitsubishi Motors Corp. went public with news it had overstated the fuel economy of its cars, Chairman Osamu Masuko visited Nissan Motor Co. President Carlos Ghosn for a mea culpa. It did not take long for talk to turn from an apology to a deal.

Three weeks after Masuko and Ghosn’s April 18 meeting, their respective boards signed off on an agreement in which Nissan will buy 34 percent of Mitsubishi Motors for about ¥237.4 billion. In purchasing the stake, Nissan will serve as a backstop for an automaker facing a mileage-rigging scandal that is threatening its existence.

Ghosn assured his MMC counterpart that Nissan “would back us up as much as possible, so hang on,” Masuko, 67, said in an interview Thursday. The two companies first agreed to form a joint venture for minicars in 2010 and had discussed deepening ties over the years. It took Nissan discovering discrepancies in the performance of the models Mitsubishi Motors supplied — and the existential crisis that followed — to push negotiations to the finish line.

“I think this alliance would have happened even without this fraud case, but it made this happen earlier,” said Masuko, who has been chairman and chief executive officer of Mitsubishi Motors since June 2014. “We started talking about what we had been talking for a long time.”

The companies plan to sign an agreement by May 25 in which Nissan can name four directors to the MMC board, including the chairman. The deal will be invalid if not completed within a year.

Mitsubishi Motors has said it manipulated the fuel economy data of the four minicar models involved in its joint venture with Nissan, and is investigating improper testing of other Japan vehicles that dates back to 1991.

The automaker will compensate owners for the fuel-cost difference in affected minicars, President Tetsuro Aikawa told reporters Wednesday. It also may have to pay back government tax rebates its minicars should not have been eligible for, the company has said.

Nissan will become the largest shareholder in Mitsubishi Motors after the deal and wield veto power over major decisions with its 34 percent stake. The combined shareholding of Mitsubishi Group companies — Mitsubishi Heavy Industries Ltd., Mitsubishi Corp. and Mitsubishi UFJ Financial Group Inc. — will fall to 22.4 percent from 34 percent.

With its 34 percent stake, Nissan should be insulated from having to shoulder some of the burden of those costs, according to Paul Newton, an analyst for researcher IHS Automotive.

“The 34 percent stake allows Nissan to remain outside of the liability threshold for Japanese companies,” Newton said in an email. “The purchase will give them an effective controlling stake and is somewhat opportunistic, as $2.2 billion is not a huge sum for such a significant chunk of the company and could be seen as something of a bargain.”

The transaction eases concerns about the viability of an automaker that has dealings with 7,777 companies affecting 410,000 people, according to Teikoku Databank Ltd. estimates. Mitsubishi Motors traces its roots back to 1917 and the Mitsubishi Model A, Japan’s first series-production car.

“We have been had these kind of discussions on potential synergies, and then when these events happened, these ongoing discussions started to little-by-little converge toward the future,” Ghosn, 62, said in an interview Thursday. “I don’t believe in anything aggressive. For partnerships to work, they have to be jointly cherished.”