Hi Daniel,
Not a good situation, but I would say that if you are as reasonable as possible you should not have a long term problem.
Is your landlord Spanish? If so that's a reasonable start as they do not tend to be as officious and more family orientated so may be more understanding. You've probably paid a deposit which you'll forfeit, but that may be all you lose, plus any furnishings etc that you are obliged to leave at the apartment.
Personally I would be upfront with your landlord, but don't offer anything more than you intend to do. But he/she may respond positively to this - the last thing you want is a difficult situation when you should be going to the airport.
You should not be at risk of a criminal record as this is a civil matter. You never know but I doubt if the landlord will seek to have you listed on any debtors records. But if this happens it will likely to be limited to Spain only and for a limited period.
I realise you say that the landlord is demanding you pay it all, but they would - probably just "tongue in cheek". Many landlord's will see this as just a usual trading hazard. The lease will not say you are obliged to pay in advance either. Of course, at the very least you need to ensure that the rent is paid up to date when you leave.
The rental market in Spain is of course quiet at this time of year and generally picks up at Easter - your landlord will know this.
You do not specify the reason for your early departure, it is a longshot, but you may wish to check and travel insurance cover you hold. The wordings vary considerably but there is a small chance that the policy may offer an indemnity to you depending on the actual cause.
You may also consider an early conversation with your Embassy just in case your landlord decides to be unreasonable.
Good luck.