As part of the heme biosynthetic pathway, catalyzes the sequential polymerization of four molecules of porphobilinogen to form hydroxymethylbilane, also known as preuroporphyrinogen (PubMed:18004775, PubMed:18936296, PubMed:19138865, PubMed:23815679). Catalysis begins with the assembly of the dipyrromethane cofactor by the apoenzyme from two molecules of porphobilinogen or from preuroporphyrinogen. The covalently linked cofactor acts as a primer, around which the tetrapyrrole product is assembled (PubMed:18936296). In the last step of catalysis, the product, preuroporphyrinogen, is released, leaving the cofactor bound to the holodeaminase intact (PubMed:18936296). {ECO:0000269|PubMed:18004775, ECO:0000269|PubMed:18936296, ECO:0000269|PubMed:19138865, ECO:0000269|PubMed:23815679}. This is the function of HMBS (hydroxymethylbilane synthase, Ensembl gene identifier ENSG00000256269).