Do I have to leave Spain if my residency permit is denied?

Do I have to leave Spain if my residency permit is denied?
If your Spanish residency permit application is denied, you will probably receive a letter giving you 15 days' notice to leave the country. But does this actually mean it's mandatory for you to leave Spain or face being deported?