Stellar archaeology shows that massive elliptical galaxies formed rapidly about ten billion years ago with star-formation rates of above several hundred solar masses per year. Their progenitors are probably the submillimetre bright galaxies at redshifts z greater than 2. Although the mean molecular gas mass (5 × 10(10) solar masses) of the submillimetre bright galaxies can explain the formation of typical elliptical galaxies, it is inadequate to form elliptical galaxies that already have stellar masses above 2 × 10(11) solar masses at z ≈ 2. Here we report multi-wavelength high-resolution observations of a rare merger of two massive submillimetre bright galaxies at z = 2.3. The system is seen to be forming stars at a rate of 2,000 solar masses per year. The star-formation efficiency is an order of magnitude greater than that of normal galaxies, so the gas reservoir will be exhausted and star formation will be quenched in only around 200 million years. At a projected separation of 19 kiloparsecs, the two massive starbursts are about to merge and form a passive elliptical galaxy with a stellar mass of about 4 × 10(11) solar masses. We conclude that gas-rich major galaxy mergers with intense star formation can form the most massive elliptical galaxies by z ≈ 1.5.