Nadal and Lopez defeated the Romanians 6-2 3-6 6-4 while American duo Steve Johnson and Jack Sock beat Canada's Daniel Nestor and Vasek Pospisil 6-2 6-4 to clinch bronze.
The doubles win sets up Nadal for a potential golden double in the men's events at the Rio Games as he is still alive in the singles draw.
Nadal, who won singles gold in Beijing eight years ago and missed the 2012 London Games due to a knee injury, will play Argentina's Juan Martin del Potro in the semi-finals on Saturday.
Nadal said his partner was a close friend even though they had little experience of playing together and were tested by a experienced Romanian pair.
ALSO READ: Rio 2016 - Nadal shocked by Djokovic's loss
"It is a privilege to be able to share this moment with one of my best friends," he told reporters.
Nadal and Lopez claimed Spain's fifth overall medal, following others in swimming, canoe slalom and weightlifting.
A gruelling match lasting two hours and 26 minutes was a challenge for Nadal who has had an exhausting schedule and cited fatigue when he pulled out of the mixed doubles on Thursday.
After two matches on Friday, the second of which stretched into the night, Nadal will have little time to recover before the singles semi-final at mid-day on Saturday.
"I will be at a disadvantage, but the scheduling is just something you have to accept," he said.
Nadal has struggled with a wrist injury this year and the left-hander, more known for his sweeping ground stokes than the serve and volley play typical of doubles, arrived in Rio having not played since withdrawing from the French Open in May.
"Just 25 days ago I couldn't even train," Nadal said, adding that he was unsure until days before the Games whether he would compete at all.
Tecau and Mergea, both 31 years old, are doubles specialists and each rank among the world's top 15 in the pairs event.