Confocal microscopes can reject out-of-focus and scattered light; however, widefield microscopes are far more common in biological laboratories due to their accessibility and lower cost. We report confocal imaging capacity on a widefield microscope by adding a spatial light modulator (SLM) and utilizing custom illumination and acquisition methods. We discuss our illumination strategy and compare several procedures for postprocessing the acquired image data. We assessed the performance of this system for rejecting out-of-focus light by comparing images taken at 1.4 NA using our widefield microscope, our SLM-enhanced setup, and a commercial confocal microscope. The optical sectioning capability, assessed on thin fluorescent film, was 0.85 ± 0.04 μm for our SLM-enhanced setup and 0.68 ± 0.04 μm for a confocal microscope, while a widefield microscope exhibited no sectioning capability. We demonstrate our setup by imaging the same set of neurons in C. elegans on widefield, SLM, and confocal microscopes. SLM enhancement greatly reduces background from the cell body, allowing visualization of dim fibers nearby. Our SLM-enhanced setup identified 96% of the dim neuronal fibers seen in confocal images while a widefield microscope only identified 50% of the same fibers. Our microscope add-on represents a very simple (2-component) and inexpensive (<$600) approach to enable widefield microscopes to optically section thick samples.