Sutta exploration of Majjhima Nikāya (Middle Length Discourses) #36 "Mahāsaccaka Sutta" (Excerpt).
In this sutta the Buddha relates himself how he overcame his greatest spiritual challenge. He had practised extreme asceticism to the point where he almost died. When he finally collapsed from total exhaustion, he remembered how he had spontaneously attained the first jhāna as a child. He realizes that the happiness of samādhi is not related to sensuality or unwholesome mindstates, and therefore should not be feared, but cultivated as an aid to enlightenment.