Mt 26:39-40: He went a little farther and fell on His face, and prayed, saying, “O My Father, if it is possible, let this cup pass from Me; nevertheless, not as I will, but as You will.” Then He came to the disciples and found them sleeping.
A few options occur to me: (1) the disciples heard the beginning of the prayer and understood its gist, but were asleep when Jesus returned. This option assumes that a "little farther" is still within earshot. (2) Jesus had previously prayed the same prayer with his disciples, and was now repeating it. We see in Mt 26 that Jesus repeats this prayer, and if we put together everything we know about that evening we realize that many events are unrecorded, so this is not unlikely. (3) The disciples asked Jesus about his crucifixion and the events surrounding it after he rose during the time they spent with him (e.g. Lk 24, Jn 20-21), and he gave the gist of his prayer. Note that the entire prayer is not recorded - only what was probably its main point.
None of these options are unlikely, and more than one might be true. I'm not sure which is "best", and I'm not sure it's possible to know.