The Portuguese word comes, unsurprisingly, from the Latin word "mare".
The Latin word bore various fruits, but with one particularity. "Mar" is a masculine word in Portuguese, but has both genders in Castilian and Catalan; it is feminine in French, it becomes masculine in Italian, and is feminine again in Romanian.
Why is this? The answer is simple: in Latin, the word belonged to the neuter gender; with the disappearance of neuter, the various Latin languages had to put the word in one of the remaining genders (masculine and feminine). In fact, Spaniards are still deciding… (In fact, in Spanish, the masculine “mar” is much more common than the feminine version.)
The Latin word has cousins in different languages. In German, we have "Meer", a synonym of "See" (which has a different origin, parallel to the English "sea"). And, yes, English has "sea", but there is also "mere", with the same origin as German "Meer" and Portuguese "mar". "Mere", however, means “lake” and is a rather rare word.
There are more cousins of “mar”. In Irish, we can call the sea “muir”. In Russian, we have “móre”. In Sanskrit, the original word gave rise to "maryādā", meaning “coast” or “boundary”, in a small semantic leap.
But where did the words “mar”, “Meer”, “móre” come from anyway?
They all came from the ancient Indo-European word "*móri", which already meant “sea” 5000 years ago. When I look at that word, I’m reminded of the word “amor”, meaning “love”. The original sea sounds a bit like love in Portuguese...