The emergence of drug resistance may increase the death rates in advanced non-small cell lung cancer (NSCLC) patients. The resistance of erlotinib, the effective first-line antitumor drug for NSCLC with the L858R mutation of epidermal growth factor receptor (EGFR), happens after the T790M mutation of EGFR, because this mutation causes the binding of adenosine triphosphate (ATP) to EGFR more favorable than erlotinib. However, the mechanism of the enhancement of the binding affinity of ATP to EGFR, which is of paramount importance for the development of new inhibitors, is still unclear. In this work, to explore the detailed mechanism of the drug resistance due to the T790M mutation, molecular dynamics simulations and absolute binding free energy calculations have been performed. The results show that the binding affinity of ATP with respect to the L858R/T790M mutant is higher compared with the L858R mutant, in good agreement with experiments. Further analysis demonstrates that the T790M mutation significantly changes the van der Waals interaction of ATP and the binding site. We also find that the favorable binding of ATP to the L858R/T790M mutant, compared with the L858R mutant, is due to a conformational change of the αC-helix, the A-loop and the P-loop of the latter induced by the T790M mutation. This change makes the interaction of ATP and P-loop, αC-helix in the L858R/T790M mutant higher than that in the L858R mutant, therefore increasing the binding affinity of ATP to EGFR. We believe the drug-resistance mechanism proposed in this study will provide valuable guidance for the design of drugs for NSCLC.