TOKYO — Toyota said on Friday that it was taking a 5 percent stake in Mazda, another Japanese automaker, and that the companies would jointly build an assembly plant in the United States and would pool resources on new technologies.

The factory’s location has not been decided, but Toyota and Mazda said they hoped the first vehicles would roll off its production lines in 2021. The plant is expected to cost $1.6 billion and to employ about 4,000 workers, they said.

Akio Toyoda, chief executive of Toyota, said in January that the carmaker would invest $10 billion in the United States over the next five years. Although plans for that spending predated the election of President Trump, the timing of the announcement was widely seen as a response to Mr. Trump’s vows to promote American manufacturing, pushing back against countries like Japan that have large trade surpluses with the United States.

Mixing appeals, rebukes and state-sponsored enticements, Mr. Trump has pushed both American and foreign-owned companies to locate factories in the United States rather than in lower-wage countries. Even before Mr. Trump was sworn in, the heating and cooling giant Carrier agreed to cut the number of jobs it planned to move to Mexico from an Indiana plant after the state added $7 million in incentives.