Portuguese is just a modern version of Galician (Galego), a Spanish dialect from northwest Spain and northern Portugal. After the expulsion of the Moors invaders in the 8th century, it became Portugal's language. Castilian (Castellano), the root of modern Spanish, is a close sibling to Galician.
Good and fluent speakers of Portuguese, Galician and Castilian can understand each other without too much effort.
I had to learn Castellian to be able to be understood in everyday situations, to attend classes and to be able work in an office with natives.
Some words are spelled the same but the phonetics are completely different ( unless you speak Brazilian Portuguese which could be argued to be closer to Gallician-Portuguese ), and although Portuguese natives can understand a bit of Castillian ( not to the level of being able to read a newspaper though ), try to get two youths from the streets of Lisbon and Madrid to talk to each other and most likely they will sadly resort to speaking in broken English.