The move comes as the automotive industry is faced with a major shift towards greener transport and greater use of information technology.
“This is a partnership in which those who are passionate about cars will work together to make ever-better cars,” Toyota president Akio Toyoda said in a statement.
Japanese carmakers are also facing uncertainty over US President Donald Trump’s drive to support US firms over foreign imports.
He has strongly criticised Toyota over its ongoing project to build a new factory in Mexico, threatening it with tariffs. Hiroshima-based Mazda has no plants in the US.
In 2015, Toyota and Mazda signed a memorandum of understanding to explore collaboration.
Toyota and Mazda said Friday that they would combine forces on key next-generation technology.
The pair will invest $1.6 billion to build a factory in the US to produce cross-over models and Toyota’s Corolla sedan starting from 2021.
The US plant will have the capacity to produce approximately 300,000 vehicles a year and create up to 4,000 jobs.
As they enhance collaboration, Toyota will take a roughly five percent stake in Mazda, which in turn would invest in Toyota.
Toyota has sold more than 10 million hybrid gasoline-electric vehicles globally, including the Prius, since 1997,
But it is struggling to develop electric vehicles as several countries announce plans to clamp down on petrol and diesel cars.
France and Britain have both said they will end sales of petrol and diesel vehicles by 2040.
Also Friday, Toyota — which lost its crown as the world’s top-selling automaker in 2016 to German giant Volkswagen — said its latest quarterly net profit jumped 11 percent to $5.6 billion with vehicle sales up in Japan and the United States, while it also lifted its annual earnings forecast.