Withdrawal
A member state can withdraw from the European Union on its own decision according to Art. 50 TEU in the Lisbon Treaty. The deal on withdrawal is decided by qualified majority in the Council and approval by the European Parliament.
After 2 years a member state may withdraw with no agreement.
Before withdrawal was only possible according to international law. - the Vienna Convention. The EU required formally unanimity to allow a country to withdraw.
In 1984 Greenland withdraw from the EU after a referendum followed by unanimous agreement in the Council.