An 8-year-old boy went missing from his Bedford-Stuyvesant school Tuesday – and was found walking along the underground tracks of a J train, cops said Wednesday.

The boy was reported missing around 12:40 p.m. after he didn’t show up for class at the Brooklyn Excelsior Charter School on Quincy Street.

Around 1 p.m., stunned straphangers who were waiting on the platform noticed the child walking on the southbound tracks of the J train at Halsey Street station and called the cops.

The commuters were able to rescue the boy from the tracks before a train could roll through.

The child was taken to Woodhull Hospital for an evaluation and was later released to his parents.

An official at Brooklyn Excelsior, which is located near the Gates Avenue J and Z stop, couldn’t immediately be reached for comment.