Stress and the written accent
A word ending in a vowel, n or s is stressed on its second-to-last syllable and any other word on its last, and a written accent marks a stress that breaks that rule, so casa and papel but café and lápiz.
From Spanish 1.