Three routes
By agreement — the simplest and the fastest. Unilaterally — only when the law or the contract allows it. Through the court — on a material breach, or a material change of circumstances.
Under article 384 of the Civil Code, you can go to court only after you send the other party an offer to terminate the contract. You file the demand after you receive a refusal, or after no answer arrives within the time stated in the offer, in the law or in the contract. If there is no such time, wait thirty days.
Form
You make the termination in the same form as the contract. If a notary certified the contract, a notary also certifies the termination.
Consequences
As a rule, what the parties performed before the termination is not returned, unless the law or the agreement of the parties says otherwise. If the reason for the termination was a material breach of the contract by the other party, you can demand compensation for the damage.
Advice
Before a unilateral refusal, read the relevant clause of the contract. A refusal without grounds makes you liable.