Japanese automakers Toyota and Mazda confirmed plans Friday to build a $1.6 billion U.S. assembly plant that would create up to 4,000 jobs as part of an extensive new alliance. Toyota said it would make the Corolla sedan at the factory instead of in Mexico as previously intended.

The sweeping partnership between the two companies includes investments in each other and collaboration on development of electric vehicles and self-driving car technology.

The deal marks a symbolically significant shift for Toyota after the company faced withering criticism from President Trump for its plans to locate Corolla production at a $1 billion factory under construction in the state of Guanajuato in central Mexico.

Toyota said Friday that it would maintain its investment and hiring plans at the Mexican plant, but it will locate additional production of the Tacoma midsize pickup at the Mexican factory instead of the Corolla compact car, which had been set to move there from an operation in Ontario, Canada.

Related:

Toyota, Mazda to build $1.6B, 4,000-job U.S. automotive assembly plant

Trump attacks Toyota for expanding in Mexico to sell in USA

Trump's move on China counterfeiting, piracy aimed at protecting U.S. jobs

The U.S. factory is set to open by 2021. The companies have not picked a location, which is likely to trigger a bidding war between states seeking to spur economic development.

Trump swiftly heralded the move. "A great investment in American manufacturing!" he tweeted Friday morning.

Toyota spokesman Scott Vazin said the company would continue to make the Corolla at its Mississippi manufacturing plant as well, and no changes are planned there.

The new plant will offer Mazda its first U.S. production since the company ended local manufacturing in recent years after its transition out of Ford ownership.

Mazda said it would make crossover models at the plant for sale in North America. Currently, all Mazda cars sold in the USA are made in other countries, according to Barclays.

Taken together, the plans are likely to be trumpeted as a victory for Trump's push to manufacture more locally sold vehicles in the USA.. He had threatened Toyota and other car companies for selling cars to American customers that were built elsewhere.

"NO WAY!" Trump said in a tweet about Toyota in January. "Build plant in U.S. or pay big border tax." A border tax was never enacted.

Toyota and other car companies vocally opposed Trump's plans to pursue sweeping changes to the North American Free Trade Agreement, which bolstered Mexican manufacturing.

The tie-up could pave the way for a broader deal, including possibly a Toyota move to acquire Mazda altogether, which would greatly accelerate industry consolidation for a sector grappling with high regulatory and technology costs.

"Today’s agreement is a testament to the positive result of two years of collaborative and deliberate discussions between the two companies, and it is a milestone in the journey to further strengthen and accelerate the partnership," Toyota and Mazda said in a statement.

As part of the deal announced Friday, Toyota is acquiring 5% of Mazda, while Mazda is acquiring 0.25% of Toyota.

In that respect, the deal resembles the global alliance between Japanese automakers Nissan and Mitsubishi and French automaker Renault.

"Toyota and Mazda have been working more closely together, so it is no surprise they will have a plant together," Autotrader.com analyst Michelle Krebs said, adding that Mazda had been searching for U.S. manufacturing capacity.

Follow USA TODAY reporter Nathan Bomey on Twitter @NathanBomey.