Mardröm means 'nightmare', and as in English, it can be used both to describe a bad dream, and figuratively, to describe a highly negative experience.
Dröm means 'dream', and Swedish also has the verb drömma (to dream). This is a word that's existed in the Swedish language for centuries and, before that, in Old Norse as draumr. It's related to its equivalents in English (dream), German (der Traum) and many other languages, even if it is written and pronounced in different ways due to how the languages have developed vowel and consonant sounds in different ways.
As for the first part of the word, the old Swedish word mara used to refer to a spirit or demon, usually believed to be female, which people thought was responsible for causing bad dreams. These spirits were written about in stores dating back to the 13th century; in one Old Norse tale, a witch helps a wife to conjure a nightmare as a punishment for the husband who abandoned her.
According to these tales, the mare would lie on sleeping people's chests, tormenting them with upsetting dreams and messing up the sleeper's hair. Not even trees were safe from the mara, and pine trees that grow in a twisted way (often on rocky, coastal terrain) are called martallar (mare-pines).
Marig also exists as a (fairly uncommon) adjective, often meaning 'knotty/twisted' in a literal sense, for example if you were describing the appearance of martallar, but also in the metaphorical sense of 'knotty', meaning 'difficult/awkward'.
In today's spoken Swedish, mara itself has quite a different meaning, as it's a shortening of maratonlopp (marathon race). It can be used more generally as a figure of speech to refer to any kind of physically exhausting activity.
Mamma, jag hade en mardröm
Mummy, I had a nightmare
Resan blev en riktig mardröm
The journey turned into a real nightmare