Given the larger size of this worm, Ascaris lumbricoides would be at the top of my differential. However, note that this worm does not contain a thick acellular cuticle and a layer of tall circumferential muscle cells as would be expected for this nematode. Instead, note that the outer cuticle is very thin and is underlain by tall epithelial cells containing mucin-producing cells. Below the epithelial layer are longitudinal and circumferential muscle cells, creating a thick muscular layer.
Finally, earthworms have a characteristic thickened band that is present near the anterior end of the worm called the clitellum. Fortunately we were able to capture a cross-section through the clitellum as shown below.
As to how this worm got into the boy's stool, I don't know if it was swallowed (would it survive the GI tract? Any volunteers to find out?) or ended up in the stool after it was passed.