The present invention provides an improved and commercially viable process for preparation of erlotinib substantially free of N-methoxyethyl impurity, namely N-[(3-ethynylphenyl)-(2-methoxyethyl)]-6,7-bis(2-methoxyethoxy)-4-quinazolinamine, and its pharmaceutically acceptable acid addition salts thereof in high purity and in high yield. According to the present invention, erlotinib or a pharmaceutically acceptable acid addition salt of erlotinib substantially free of N-methoxyethyl impurity is prepared by isolating erlotinib or a pharmaceutically acceptable salt of erlotinib from a solvent medium comprising dimethyl sulfoxide and an alcoholic solvent.