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. There's no way that you won't come across as jumping ship - that's exactly what you're doing. That amicable relationship may sour very quickly when you express your desire to do so.
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.
One Advantage: Some companies don't feel comfortable having someone work on their project whom they know is not fully committed. When you have one foot out the door they may prefer to simply let you go right away, especially if it's a sensitive matter (revoke access, etc.). This will depend on how much they need you, and how niche your knowledge is, however.