We used event-related functional magnetic resonance imaging (fMRI) to measure brain activity when subjects were performing identical tasks in the context of either a task-set switch or a continuation of earlier performance. The context, i.e., switching or staying with the current task, influenced medial frontal cortical activation; the medial frontal cortex is transiently activated at the time that subjects switch from one way of performing a task to another. Two types of task-set-switching paradigms were investigated. In the response-switching (RS) paradigm, subjects switched between different rules for response selection and had to choose between competing responses. In the visual-switching (VS) paradigm, subjects switched between different rules for stimulus selection and had to choose between competing visual stimuli. The type of conflict, sensory (VS) or motor (RS), involved in switching was critical in determining medial frontal activation. Switching in the RS paradigm was associated with clear blood-oxygenation-level-dependent signal increases ("activations") in three medial frontal areas: the rostral cingulate zone, the caudal cingulate zone, and the presupplementary motor area (pre-SMA). Switching in the VS task was associated with definite activation in just one medial frontal area, a region on the border between the pre-SMA and the SMA. Subsequent to the fMRI session, we used MRI-guided frameless stereotaxic procedures and repetitive transcranial magnetic stimulation (rTMS) to test the importance of the medial frontal activations for task switching. Applying rTMS over the pre-SMA disrupted subsequent RS performance but only when it was applied in the context of a switch. This result shows, first, that the pre-SMA is essential for task switching and second that its essential role is transient and limited to just the time of behavioral switching. The results are consistent with a role for the pre-SMA in selecting between response sets at a superordinate level rather than in selecting individual responses. The effect of the rTMS was not simply due to the tactile and auditory artifacts associated with each pulse; rTMS over several control regions did not selectively disrupt switching. Applying rTMS over the SMA/pre-SMA area activated in the VS paradigm did not disrupt switching. This result, first, confirms the limited importance of the medial frontal cortex for sensory attentional switching. Second, the VS rTMS results suggest that just because an area is activated in two paradigms does not mean that it plays the same essential role in both cases.