Where it came from
Portuguese started as a dialect spoken in a damp corner of the northwest of Iberia, in territory nobody had much reason to fight over. A thousand years later it was being spoken in Goa, Macau, Luanda and Rio.
The history is worth a little of your time, because several things that look arbitrary in the modern language stop looking arbitrary once you know where the layers came from.
Rome, and the language underneath
The Romans reached Iberia in 218 BC and brought the Latin of soldiers and traders rather than the Latin of Cicero. It mixed with Celtic and Iberian speech already there, and by the ninth century the result, Galician-Portuguese, was what people in the County of Portugal spoke.
That layer is still the load-bearing one. Falar, comer, casa: the words you use every hour of every day are the ones that came from there and barely changed.
Five centuries of Arabic
The Moorish presence in the south, in al-Gharb which became the Algarve, lasted roughly five hundred years. The grammar stayed Latin. The vocabulary did not.
Farming, science, administration, all of it picked up Arabic terms, and there is a giveaway: words starting with "al-" usually carry the Arabic definite article fossilised into them. Azeite, olive oil. Açúcar, sugar. Alfândega, customs, which is a word about bureaucracy that arrived along with the bureaucracy.
The ships
The fifteenth and sixteenth centuries changed everything. Portuguese sailors carried the language to Africa, Asia and South America, and brought thousands of words back the other way. Camões published Os Lusíadas in 1572 and the written standard largely settled around it.
Here is the part that matters for a learner. The language went out and changed everywhere it landed, while the version left at home stayed comparatively conservative in its sounds and its syntax. The mainland kept the older pronoun placement and the older phonology. What you are learning is, in several respects, the more archaic variety, which is not the usual direction of travel.
The twentieth century and the spelling wars
Most of the modern story is about spelling, and about who gets to decide it. The Orthographic Accord of 1990 set out to unify written Portuguese across every country that uses it. It succeeded on paper and remains unpopular with a good number of Portuguese writers, which is worth knowing before you raise it at dinner.
The practical upshot for you: a Brazilian newspaper is perfectly readable. A conversation in a Lisbon café is a separate skill, and no accord was ever going to fix that.