The agreement you reached at the start could still be legally binding, even if its terms were not specifically mentioned in the contract you were subsequently issued with. A contract is formed when there is an offer, acceptance and consideration so if they offered you the job on the basis of it being a 24 month minimum contract and you accepted it, a binding contract is likely to have been created on these terms even if it was not included in the formal employment contract.
If you were to breach the agreement and leave earlier, the employer then has the option of suing the employee to seek compensation for damages resulting from their breach. However, in reality such claims are very rarely made. This is mainly due to the costs and time involved, also the relatively small damages that can be recovered. Also the employer has to show that actual losses have been incurred and often that is not easy to do. Also if you are willing to serve your notice period and they find a replacement in the meantime, their losses are likely to have been offset or completely removed. So whilst there is no way of predicting whether the employer will take this any further or not, chances are that they will not. A more likely outcome is that the employer refuses to provide a reference in the future or if they do, it could mention that the employee had breached their contract.
Finally, there are circumstances when an employee may be entitled to leave with immediate effect and without honouring their contract. This occurs when an employer has committed a serious breach of contract first. The whole contract then becomes immediately void and the employee would be treated as being 'constructively dismissed'. So if there are reasons to believe the employer has acted in breach of contract, whether a breach of an express contractual term, or other breaches such as bullying, exposing the employee to unreasonable stress, discriminating against them, etc this reason can be relied on in order to leave earlier than agreed.
I hope this has answered your query. I would be grateful if you could please take a second to leave a positive rating (3, 4 or 5 stars) as that is an important part of our process and recognises the time I have spent assisting you. If you need me to clarify anything before you go - please get back to me on here and I will assist further as best as I can. Thank you