In 1986, DC Comics published the Man of Steel mini series which retconned Superman's origin and history. In this version of Superman, he never started his career in his youth. The history of Superboy and his growing up to be Superman was erased from DC Comics' continuity. The post Crisis Superman from the Man of Steel mini series replaced the previous version of Superman. In 1987, Legion of Super-Heroes #37, Superman #8, Action Comics #591 and Legion of Super-Heroes #38 explained how Superboy was able to exist in the history of the DC Universe.
The Legion of Super-Heroes discovers anomalies in history that does not coincide with their version of history including historical data about Superman. The Time Trapper seems to be responsible for manipulating the time stream (See Cosmic Boy mini series and Legends).
The Legion decides to travel in the Time Bubble to confront the Time Trapper at the end of time. The Time Trapper diverts the Legion to Superboy's time period where some members of the Legion are captured by Superboy.
The others escape in the Time Bubble several years into the future and land in Superman's time period. The Legion and Superman meet for the first time which confuses members of the Legion except for Brainiac 5. Superboy is able to follow the Legion and captures them as well.
Superboy brings them back to the past with Superman following him. Superboy and Superman battle in Smallville after arriving in the past. Superboy does not wish to fight anymore and explains his actions. Superman is returned to his own time period while Superboy and the Legion of Super-Heroes leave to battle the Time Trapper.
The Time Trapper reveals he altered the timeline to create a pocket universe that contained the Superboy of an alternate Earth. Apparently, the Time Trapper diverted any travel by the Legion to Superman's early years to the Earth in this pocket universe. Thus, the Legion invited the Superboy from this pocket universe to be a Legionnaire. The Time Trapper created Superboy as part of a trap to destroy the Legion.
The Time Trapper coerced Superboy's cooperation by saving his home and family from a destructive storm of energy that could still be released to destroy them. Superboy dies to save his Earth from destruction and to save the Legion from the Time Trapper. Time travel is also stopped until Brainiac 5 finds another way through time.