South Africa's men's and women's teams will both play hosts Brazil in the group stage of the 2016 Olympics.
The men have been drawn in Group A, along with Iraq and Denmark. The women are in Group E, with China and Sweden.
Brazil's men were runners-up in 2012, the women runners-up in 2008. Both teams are expected to be tough opponents in their home country.
Fifty eight matches - 32 for the men, 26 for the women - will be played in the tournament from 3 to 20 August.
Full draw for the Olympic Football Tournament Rio 2016:
Brazil, South Africa, Iraq, Denmark
Sweden, Colombia, Nigeria, Japan
Fiji, Korea Republic, Mexico, Germany
Algeria, Portugal, Honduras, Argentina
Brazil, China, Sweden, South Africa
Canada, Zimbabwe, Australia, Germany
USA, New Zealand, France, Colombia