The World Anti-Doping Agency (WADA) has confirmed that it has lifted the provisional suspension of the Brazilian Doping Control Laboratory ahead of the Rio Olympics and Paralympics.
The crucial decision means drug-test samples from the Games will not need to be taken out of Brazil for analysis.
WADA suspended the laboratory's accreditation last month - just 42 days before the Olympic Opening Ceremony on August 5.
This was due to "procedural errors" with the facility not compliant with International Standard for Laboratories (ISL) rules.
Now, officials have successfully brought the laboratory into line to avoid a logistical nightmare during the Games.
No further suspension is required, WADA confirmed.
"WADA is very pleased to announce that the Rio Laboratory’s accreditation has been reinstated,” said Olivier Niggli, WADA's director general.
"All parties worked diligently to resolve the identified issue so that the laboratory could be up and running optimally for the Rio Olympic and Paralympic Games that start on August 5."
"Athletes can be confident that anti-doping sample analysis has been robust throughout the laboratory’s suspension, and, that it will also be during the Games."
Brazilian Sports Minister Leonardo Picciani predicted that the suspension would be overturned earlier this month.
It could have cost as much as $250,000 (£182,000/€224,000) to test samples elsewhere - a scenario which happened during the 2014 FIFA World Cup in Brazil when a laboratory in Switzerland, more than 9,000 miles away, was used.
Former WADA director general David Howman, who was replaced by Niggli earlier this month, had hinted that the Rio laboratory would not have its accreditation restored in time.
He said it would be "unlikely" the facility would be back running in time for the Games.
The lab has encountered numerous problems in the past after it had its accreditation revoked in 2013 for failing a "blind" quality assessment test.
In 2012, it was suspended from conducting isotope ratio mass spectrometry (IRMS) testing on samples for several months before being reinstated.
A number of WADA-accredited labs have recently been suspended.
These include Almaty, Bloemfontein, Beijing, Lisbon and Madrid, while Moscow's status has been revoked due to the Russian doping scandal.