Prophet (blessings and peace of Allah be upon him) said: "Fasting is half of patience." Narrated by at-Tirmidhi.
Patience is of three types: patience in obeying Allah, patience in refraining from that which Allah has prohibited, and patience in accepting the decree of Allah when it is hurtful. All three types of patience are combined in fasting.
End quote from Lataa'if al-Ma'aarif by Ibn Rajab (p. 150)
The fasting person gives up the desires of his nafs that he is naturally inclined to love and to give precedence to over other things, and that are also necessary for him, but the fasting person gives precedence to love of his Lord over these things, so he gives them up in a manner that no one could know about except Allah, so his love for Allah becomes more important and overwhelms any other natural inclinations, and seeking the pleasure of his Lord takes precedence over attaining his own whims and desires.