Rajoy and Temer held talks in the capital Brasilia. The two leaders then met with heads of Spanish telecommunication, energy and financial firms.
“A new era is starting… for Spanish investments in our country,” Temer told journalists afterward.
One of the world's biggest emerging markets, Brazil is forecast to exit a more than two-year recession this year, although only just. It is also in the throes of a huge corruption scandal, with a third of Temer's government under investigation.
Rajoy said Brazil “has very ambitious plans for its economy, matching the the immense potential of this country.”
“I am absolutely convinced that there is a lot of scope to increase the presence of Spanish companies in Brazil,” he said.
Rajoy urged progress on a delayed free trade deal between the European Union and the Mercosur bloc, consisting of Argentina, Brazil, Paraguay and Uruguay. He criticized “the temptation of protectionism.”
Rajoy was due later in Sao Paulo, Brazil's financial hub, where he will attend a conference with some 200 business leaders.
“Brazil is opening up and Spanish companies want to compete,” a Spanish government official, who asked not to be named, told journalists.
On the violent chaos and economic meltdown in Venezuela, Rajoy said: “We are deeply worried.”
The Spanish premier said a compromise between President Nicolas Maduro and the opposition was inevitable, “giving the word back to the Venezuelan people.”
Brazil is Spain's third biggest export market, with bilateral trade worth $5.6 billion in 2016.