This type of dilemma occurs often in life but the main thing to remember is that it is YOUR life.
So don't be afraid to make the right decision for YOU.
Wait until you know definitely if you get a position with Y.
Then contact X and be honest, apologise for mucking them around and any...