Toyota Motor Corp. and Mazda Motor Corp. have agreed to buy stakes in each other and jointly build a $1.6 billion U.S. factory, as carmakers band together to share costs and investments in new technology.

Toyota will acquire about 5 percent in Mazda, which will hold a 0.25 percent in the bigger automaker in a capital tie-up, according to a Japanese regulatory filing. The planned car plant will create about 4,000 jobs.

Mazda rose 2.8 percent, while Toyota declined 0.1 percent at the close of trading in Tokyo.

Mazda lacks any U.S. factories, which exposes one of Japan’s smallest carmakers to both trade and currency risk. President Donald Trump threatened to tax auto imports early in his presidency and specifically attacked Toyota’s plan to open a Corolla plant in Mexico. Shifting production of those cars from a plant in Canada enables Toyota to boost output of the RAV4 crossover. American consumers are buying that model in record numbers, while Mazda also is seeing booming demand for its entry in that segment, the CX-5.

Trump’s pressure to build more vehicles in the U.S. may have affected the timing of Mazda’s decision to start manufacturing cars in the U.S., as well as Toyota’s decision to boost its presence, said John Shook, chief executive of the Lean Enterprise Institute in Cambridge, Massachusetts. But their close relationship has been in development for many years, he said.

“Mazda has been studying the Toyota Production System, with direct help from Toyota, since the 1970s,” said Shook, a former Toyota engineer. “So this is an easy marriage for both parties.”

EV Work

The deepening ties between Toyota and Mazda also are driven in part by the enormous costs automakers are facing to develop connected, self-driving and battery-powered vehicles. The two companies will work together to develop electric vehicle technology, according to the filing.

Toyota has sought to share the costs of developing new technologies—and spread the expense of building traditional vehicles—with a growing set of its Japanese peers in recent years. The company solidified a partnership with Suzuki Motor Corp. in February and already sources compact cars from Mazda’s lone North American assembly plant in Mexico. Until last year, Subaru Corp. built the Camry for Toyota at a factory in Indiana.

“In Japan, there’s a great tradition of Toyota being a ‘big brother’ to other smaller manufacturers,” said Eric Noble, founder of The Carlab, an automotive consultancy in Orange, California. Because of its strong dependence on North American market, Mazda absolutely needs to expand its manufacturing footprint here.”

The Nikkei newspaper reported earlier the capital tie-up and plans for a U.S. car plant, without saying where it got the information.