The mariner is cursed because he shot and killed the albatross, which is a sea-going bird that was thought to be a good luck omen. The mariner shoots and kills it for no apparent reason. Because of this, the sailors make him wear it around his neck to remind him of his sin. Once the mariner atones for his sin, the albatross drops from his neck into the water below the ship.
The punishment for the mariner takes many forms. First, he suffers physically and mentally for his sin. Second, the crew dies and he has to live with the fact he caused it. Third, he must tell his story the rest of his days to a chosen person that needs to hear it in order to teach them to respect nature and to revere God and His creatures.
The curse is released once the mariner gains a new-found respect for nature:
The moral of the tale is manifest in the ancient mariner's final words to the wedding guest: "He prayeth best, who loveth best/ All things both great and small;/ For the dear God who loveth us,/ He made and loveth all." (eNotes)