The math problem solved while stepping onto a carriage
Henri Poincaré's own account of "unconscious mathematics": the insight that struck as he boarded an omnibus on a geology trip.
Fifteen days of struggle
Around 1880, the French mathematician Henri Poincaré was working on a new class of functions he would later name Fuchsian functions. For fifteen days he sat at his desk trying combination after combination, without reaching the result he wanted.
Then he set the mathematics aside to join a geological excursion. In Coutances, in Normandy, as he put his foot on the step of an omnibus to go somewhere with his companions, the idea came to him without warning: the transformations he had been using were the same as those of non-Euclidean geometry. He kept up the conversation and did not check it then, but he wrote that he felt complete certainty.
What he wrote himself
Poincaré described this experience in detail in the essay "Mathematical Creation," included in Science and Method (1908). He stressed that sudden illumination comes only after long periods of conscious effort, and that ideas which arrive this way must always be verified. Indeed, after returning home he checked the result at leisure.
What intuition did
Poincaré's account was later distilled in creativity research into four stages, preparation, incubation, illumination and verification, and became widely known. Stepping away after thinking hard can be exactly what brings the answer.
Sources: Henri Poincaré, Science and Method (Science et méthode), 1908.