Siddhartha Gautama discovered the Middle Path upon contemplation of his practiced lifestyles. He understood that the moderate path with no extremes would be the best.
Now that Gautama had seen and practiced both extremes of life, he had realised that neither of the two extremes would do any good to him or any individual who would indulge in them. He was now convinced that self harm was no good. Despite the fact that it was considered essential for enlightenment in his day, it actually weakened the body and intelligence.
He thus gave up this extreme of painfulness as he had given up indulgence in his life as a prince. He then thought about swaying towards neither side but rather living a life which would be the mean of these two. This would later be known as the Middle Path.
Gautama then recalled the ploughing incident in his childhood and how he had attained the first jhāna. He realised that this was the path of enlightenment; by living by the Middle path and meditating as he did back then, he can attain his goal.
Realising that enlightenment cannot be achieved with a weak and exhausted body, he decided to take care of his body. Even when his companions had left him alone, he did not lose hope. Contrary, it benefitted him in the same manner as it did when they had accompanied him in struggles.
After his enlightenment, this concept of moderation was manifested as the Eightfold Noble Path. Which is now considered a means to live by moderation and achieve enlightenment with practice.