Given right context, they could be both correct.
in a story: "I stopped to smoke two years ago." could be telling a clause that involves a past event happening at a time when the character was stopping to smoke.
But in every day dialogue "I stopped smoking two years ago" is a much more common situation.