One region thought to play a role in OCD is the basal ganglia, a collection of structures underneath the cortex that help coordinate movement; when the basal ganglia malfunctions, unwanted, involuntary movements can result.
In addition to the motor cortex, the basal ganglia also communicates with the prefrontal cortex, which is involved in planning, thinking, and awareness, so the basal ganglia may play a part in facilitating wanted thoughts and stopping unwanted thoughts. As evidence for this idea, brain activity in the cortex and basal ganglia is different in OCD and typical individuals, and stimulating part of the basal ganglia can reduce symptoms of OCD.