Despite the high inhibition of viral replication achieved by current anti-HIV drugs, many patients fail treatment, often with emergence of drug-resistant virus. Clinical observations show that the relationship between adherence and likelihood of resistance differs dramatically among drug classes. We developed a mathematical model that explains these observations and predicts treatment outcomes. Our model incorporates drug properties, fitness differences between susceptible and resistant strains, mutations and adherence. We show that antiviral activity falls quickly for drugs with sharp dose-response curves and short half-lives, such as boosted protease inhibitors, limiting the time during which resistance can be selected for. We find that poor adherence to such drugs causes treatment failure via growth of susceptible virus, explaining puzzling clinical observations. Furthermore, our model predicts that certain single-pill combination therapies can prevent resistance regardless of patient adherence. Our approach represents a first step for simulating clinical trials of untested anti-HIV regimens and may help in the selection of new drug regimens for investigation.