Animals are expected to select a breeding habitat using cues that should reflect, directly or not, the fitness outcome of the different habitat options. However, human-induced environmental changes can alter the relationship between habitat characteristics and their fitness consequences, leading to a maladaptive habitat choice. The most severe case of such nonideal habitat selection is the ecological trap, which occurs when individuals prefer to settle in poor-quality habitats while better ones are available. Here we studied the adaptiveness of nest box selection in a tree swallow (Tachycineta bicolor) population breeding over a 10-year period in a network of 400 nest boxes distributed along a gradient of agricultural intensification in southern Québec, Canada. We first examined the effects of multiple environmental and social habitat characteristics on nest box preference to identify potential settlement cues. We then assessed the links between those cues and habitat quality as defined by the reproductive performance of individuals that settled early or late in nest boxes. We found that tree swallows preferred nesting in open habitats with high cover of perennial forage crops, high spring insect biomass, and high density of house sparrows, their main competitors for nest sites. They also preferred nesting where the density of breeders and their mean number of fledglings during the previous year were high. Additionally, we detected mismatches between preference and habitat quality for several environmental variables. The density of competitors and conspecific social information showed severe mismatches, as their relationships to preference and breeding success went in opposite direction under certain circumstances. Spring food availability and agricultural landscape context, while related to preferences, were not related to breeding success. Overall, our study emphasizes the complexity of habitat selection behavior and provides evidence that multiple mechanisms may potentially lead to an ecological trap in farmlands.