I'd like to start by mentioning that you should always keep your own interests foremost in mind.
Companies will certainly do the same, and they will not hesitate to make a decision that potentially harms you if it is in their interest.
If you have a good working relationship with your employer, then simply be honest with them. Maybe offer to work evening on their project while they get someone else on board, and help brief whomever they hire next about your work so that the transition will be as smooth as possible.
However make no mistake that by leaving early you are screwing your employer over. That amicable relationship may sour very quickly.
Face the fact that you might simply have to stick to the terms of your contract if you don't want to burn your bridges, or unless you're prepared to deal with the consequences of breaching it.
You don't mention what those consequences might be, but if they are severe you may want to seek legal counsel before you initiate the conversation just in case it doesn't go over well.