Flow is the state of full attention to the task at hand. It is typically studied in daily life, as people engage deeply in activities such as art, sports, and leisure, and typically its affective characteristics are emphasized. This research investigates flow in the laboratory, focusing on its cognitive characteristics. Participants completed different versions of the Trail Making test, a measure of executive function, that made parametrically increasing demands on attention. As predicted, more participants were in the flow state when attentional demands were moderate than when they were low or high. This was revealed by conventional survey measures indicating a balance between the perceived challenge of the task and the perceived skill of participants. Critically, this was also evidenced by a new operational measure of time distortion, defined as the difference between people’s subjective estimates of their task completion times and the objective, experimenter-recorded times. Participants experienced downward time distortion—the feeling of time flying—when attentional demands were moderate. These findings demonstrate for the first time the causal role of attentional demands in inducing the flow state. They set the stage for future studies of flow and time distortion using attention-demanding cognitive tasks, and of the association between time perception and creative thinking.