Mediterranean fruit flies (Ceratitis capitata Wiedemann, Dipt.: Tephritidae) harbour a diverse community of bacteria in their digestive system. This microbiota may have important functions impacting on the fly’s fitness. Recently, we described the effect of eliminating intestinal bacteria on the reproductive success of C. capitata males and females. Here, we expand the view on the nature of fly–bacteria interactions by examining the effect of bacteria on male and female longevity. Antibiotics were used to suppress the gut bacterial community and mortality rates were compared between antibiotic-treated and non-treated flies when either nutritionally stressed (maintained on sugar) or provided with a full diet. These tests revealed that eliminating the gut bacterial population prolonged longevity, but only when flies were nutritionally stressed, indicating that the effect of bacteria on lifespan was diet dependent. Considering these results in light of other known effects of bacteria on fitness components of the fly demonstrates a cost-benefit relationship between C. capitata and its gut microbiota.