Yes, if you still spend most of the time in Portugal.
You can change the details of your trip after the visa was granted if the premise remains unchanged and if the changes came genuinely after the visa was granted. You should avoid giving the appearance of 'visa-shopping' (that mmeans misrepresenting your itinerary so that another consulate would be responsible for your application).
Your planned change would not affect that you are still goint to Portugal. On arrival in Spain, you would have plans and documents to show that you are immediately going to Portugal, and if asked you can show them.