When the distance between a visual target and nearby flankers falls below a critical distance, target discrimination declines precipitously. This is called "crowding." Many researchers have proposed that selective attention plays a role in crowding. However, although some research has examined the effects of directing attention toward versus away from the targets, no previous research has assessed how attentional allocation varies as a function of target-flanker distance in crowding. Here, we used ERPs to assess the operation of attention during crowding, focusing on the attention-related N2pc component. We used a typical crowding task in which participants were asked to report the category (vowel/consonant) of a lateralized target letter flanked by distractor letters at different distances. We tested the hypothesis that attention fails when the target-flanker distance becomes too small for attention to operate effectively. Consistent with this hypothesis, we found that N2pc amplitude was maximal at intermediate target-flanker distances and decreased substantially when crowding became severe. In addition, we examined the sustained posterior contralateral negativity (SPCN), which reflects the amount of information being maintained in working memory. Unlike the N2pc component, the SPCN increased in amplitude at small target-flanker distances, suggesting that observers stored information about the target and flankers in working memory when attention failed to select the target. Together, the N2pc and SPCN results suggest that attention and working memory play distinctive roles in crowding: Attention operates to minimize interference from the flankers at intermediate target-flanker distances, whereas working memory may be recruited when attention fails to select the target at small target-flanker distances.