FIFA president Sepp Blatter, Dick Pound, chairman of the World Anti-Doping Agency, and Jacques Rogge, president of the International Olympic Committee, took the stage at FIFA's Centennial Congress in Paris to sign FIFA's declaration.
"This is an historic day for sport and the battle against doping in sport," Pound told the Congress. "This is a major step forward."
"This is the end of it, football will now be at the Olympic Games. It is just up to FIFA now to incorporate this into their own process, but this is the end of debate and I am delighted."
Rogge said: "I have been to many weddings and you hope the bride and groom will be happy. I am sure this marriage between FIFA and WADA will be a long one and produce good children."
All sports have to sign up to WADA's code if they want to take part in the Athens Games. Only cycling has now to sign.
Earlier this week it seemed that soccer, which has been part of the Olympic Games since 1908 with the exception of the 1932 Games in Los Angeles, could be dropped from the programme.
The issue of what FIFA terms "individual case management" -- dealing with each case on its merits rather than subscribing to automatic two-year bans -- has held up the agreement.
WADA also wanted to retain the right to appeal to the Court of Arbitration for Sport (CAS) if it disagrees with any FIFA ruling. This has also provided a sticking point but, according to both sides, these issues are now solved.
"We are delighted to sign up to this code," Blatter said. "We have to fight doping and stop it."
Soccer's world governing body has been perceived to be weak on the doping issue over the last few years with relatively lenient sanctions being imposed on players like Dutchmen Edgar Davids and Jaap Stam for nandrolone-related offences.
England defender Rio Ferdinand was handed an eight-month ban for forgetting to take a doping test last September, which would have earned him a two-year ban if he had been a track and field athlete.