Birds have a highly specialized and efficient digestive system, but when this system originated remains uncertain. Here we report six gastric pellets attributable to the recently discovered 160-million-year-old troodontid dinosaur Anchiornis, which is among the key taxa for understanding the transition to birds. The gastric pellets contain lightly acid-etched lizard bones or fish scales, and some are associated with Anchiornis skeletons or even situated within the oesophagus. Anchiornis is the earliest and most basal theropod known to have produced gastric pellets. In combination with other lines of evidence, the pellets suggest that a digestive system resembling that of modern birds was already present in basal members of the Paraves, a clade including troodontids, dromaeosaurids, and birds, and that the evolution of modern avian digestion may have been related to the appearance of aerial locomotion in this lineage.