Organoid models of early tissue development have been produced for the intestine, brain, kidney and other organs, but similar approaches for the heart have been lacking. Here we generate complex, highly structured, three-dimensional heart-forming organoids (HFOs) by embedding human pluripotent stem cell aggregates in Matrigel followed by directed cardiac differentiation via biphasic WNT pathway modulation with small molecules. HFOs are composed of a myocardial layer lined by endocardial-like cells and surrounded by septum-transversum-like anlagen; they further contain spatially and molecularly distinct anterior versus posterior foregut endoderm tissues and a vascular network. The architecture of HFOs closely resembles aspects of early native heart anlagen before heart tube formation, which is known to require an interplay with foregut endoderm development. We apply HFOs to study genetic defects in vitro by demonstrating that NKX2.5-knockout HFOs show a phenotype reminiscent of cardiac malformations previously observed in transgenic mice.