Previous to Prospero and Miranda arriving on the island the spirits there were enslaved by a witch called Sycorax, the mother of Caliban. She imprisons Ariel in a pine cone for disobedience. Prospero releases Ariel, but keeps him under his command and when disobedient reminds him that he owes his freedom from enslavement to him. Ariel creates the storm that drives the ship carrying the sailors and Alonso etc to Prospero unharmed. In the play he acts as the eyes and ears of Prospero, informing him of the Caliban conspiracy. He has power over the elements and in Act three he appears in a clap of thunder to adminish those who had treated Prospero so badly in Milan.
It is the magic of Ariel that makes Miranda and Ferdinand fall in love and for that act more than any other Prospero agrees to free him once he has had a safe passage back to Milan with the rest of the crew. It is Ariel that allows the happy conclusion of the play.
He is released back into the elements and Prospero destroys his magic books.