Background: Extended-spectrum β-lactamase-producing Escherichia coli (ESBL-EC), plasmid-mediated AmpC-producing E coli (pAmpC-EC), and other bacteria are resistant to important β-lactam antibiotics. ESBL-EC and pAmpC-EC are increasingly reported in animals, food, the environment, and community-acquired and health-care-associated human infections. These infections are usually preceded by asymptomatic carriage, for which attributions to animal, food, environmental, and human sources remain unquantified. Methods: In this population-based modelling study, we collected ESBL and pAmpC gene data on the Netherlands population for 2005–17 from published datasets of gene occurrences in E coli isolates from different sources, and from partners of the ESBL Attribution Consortium and the Dutch National Antimicrobial Surveillance System. Using these data, we applied an established source attribution model based on ESBL-EC and pAmpC-EC prevalence and gene data for humans, including high-risk populations (ie, returning travellers, clinical patients, farmers), farm and companion animals, food, surface freshwater, and wild birds, and human exposure data, to quantify the overall and gene-specific attributable sources of community-acquired ESBL-EC and pAmpC-EC intestinal carriage. We also used a simple transmission model to determine the basic reproduction number (R0) in the open community. Findings: We identified 1220 occurrences of ESBL-EC and pAmpC-EC genes in humans, of which 478 were in clinical patients, 454 were from asymptomatic carriers in the open community, 103 were in poultry and pig farmers, and 185 were in people who had travelled out of the region. We also identified 6275 occurrences in non-human sources, including 479 in companion animals, 4026 in farm animals, 66 in wild birds, 1430 from food products, and 274 from surface freshwater. Most community-acquired ESBL-EC and pAmpC-EC carriage was attributed to human-to-human transmission within or between households in the open community (60·1%, 95% credible interval 40·0–73·5), and to secondary transmission from high-risk groups (6·9%, 4·1–9·2). Food accounted for 18·9% (7·0–38·3) of carriage, companion animals for 7·9% (1·4–19·9), farm animals (non-occupational contact) for 3·6% (0·6–9·9), and swimming in freshwater and wild birds (ie, environmental contact) for 2·6% (0·2–8·7). We derived an R0 of 0·63 (95% CI 0·42–0·77) for intracommunity transmission. Interpretation: Although humans are the main source of community-acquired ESBL-EC and pAmpC-EC carriage, the attributable non-human sources underpin the need for longitudinal studies and continuous monitoring, because intracommunity ESBL-EC and pAmpC-EC spread alone is unlikely to be self-maintaining without transmission to and from non-human sources. Funding: 1Health4Food, Dutch Ministry of Economic Affairs, and the EU's Horizon-2020 through One-Health European Joint Programme.