Abstract The present communication concerns a detailed analysis of metal flow into a porthole extrusion die to produce a thin-walled square magnesium tube by means of three-dimensional FE simulation in both the transient state and steady state. The research was aimed to get an insight into the longitudinal weld seam formation during extrusion through porthole dies and to evaluate the factors determining the quality of the weld seams. FE simulation revealed distinctive stages at the beginning of an extrusion cycle, corresponding to the changes in extrusion pressure during the process. It showed that the commonly observed defect at the extrudate head was due to entrapped air under the bridges in the upper part of the welding chamber. The dead metal zones existed at the corners between the container and die face and between the bottom and sidewall of the welding chamber. Because of the friction at the die bearing, the metal flow through the die bearing resembled laminar flow. Only the virgin metal from the interior of the billet flowed along the bridges and formed the welding seams. As ram speed increased, the mean stresses and temperatures on the welding plane in the welding chamber increased, which was reflected in the increases in extrusion pressure and extrudate temperature, being beneficial to the solid-state bonding at the weld seams. Tensile tests confirmed that extrusion at a higher ram speed led to enhanced transverse tensile strength and strain of the extruded square tube, as a result of improved bonding at the longitudinal weld seams.