The endodermal midgut arises from two primordia, the anterior midgut (AMG) primordium and the posterior midgut (PMG) primordium, which are separated by almost the entire length of the Drosophila embryo. To form the midgut, these two parts have to extend towards each other and to fuse laterally on both sides of the yolk. Shortly before and during that movement, AMG and PMG are arranged as mesenchymal cell masses, but later the midgut cells form an epithelium. We show that these two aspects of midgut development, migration of AMG and PMG and transition to an epithelium, depend on the mesoderm. The extension of the midgut primordia is achieved by cell migration along the visceral mesoderm which forms a continuous layer of cells within the germ band. In mutant embryos lacking the entire mesoderm or failing to differentiate the visceral mesoderm, AMG and PMG are formed but do not migrate properly. In addition, they fail to form an epithelium and instead either remain as compact cell masses anterior and posterior to the yolk (in twist and snail mutant embryos) or only occasionally wrap around the yolk before embryogenesis is completed (in tinman-deficient embryos). We conclude that the visceral mesoderm serves as a substratum for the migrating endodermal cells and that the contact between visceral mesoderm and endoderm is required for the latter to become an epithelium.