The genes were isolated by comparing the genetic profiles of people in their first year of HIV infection with those who managed to resist infection despite repeated exposure to the virus.
The "good" versions of the two genes were present in 12.2 percent of those who resisted infection compared with only 2.7 of patients in primary HIV infection.
Researchers are not yet sure how this protection works.
One of the genes codes for a receptor on the surface of the immune system's natural killer cells which destroy infected cells in the body.
The other codes for a protein which binds the first gene and dampens the natural killer cell activity.
The most likely explanation is that HIV prevents the protein that dampens the killer cell activity from being expressed, allowing the killer cells to destroy cells infected with HIV.
Since this can happen very soon after the initial infection, people carrying those genes may be able to more efficiently destroy infected cells and lower their chances of developing AIDS.
"More research is needed to determine the exact mechanism behind the protection we have observed, but these findings have revealed a promising avenue," said co-author Nicole Bernard of the Research Institute of the McGill University Health Centre.
"In the future, our findings could be used to somehow 'boost' the innate immune system and thus fight the virus as soon as it enters the body."
The study was published Wednesday in the journal AIDS.