Sleep corresponds predominantly with the PNS (Parasympathetic Nervous System). Activity corresponds predominantly with the SNS (Sympathetic Nervous System). These systems always work together but, generally speaking, one is more dominant than the other in MOST cases As an interesting aside, sexual arousal is an exception to this where they work in a delicate orchestration.
Anyway, the PNS and SNS are the two components of what creates the Autonomic Nervous System (ANS) which controls mostly involuntary functions. The tricky thing about the ANS is that when one side gains control of the body, it creates a cascading effect that causes things like relaxation and arousal. These cascades take time to "warm up" and "cool down" so if you get very active before bed, then the SNS takes control and causes immediate changes like increases in heart rates, breathing rates, body temp, sweat production, etc. However, it also causes a cascade effect where stress hormones course through your body. This will keep you alert for a rather long period of time as cortisol, epinephrine, norepinephrine and other hormones go through your blood stream and need to be diminished over time.
This is the same reason why you should leave the room after you just get into a fight with someone and "cool down". If you stay in the same room with them, the cascade effect of hormones and other factors effects the psyche. You need the SNS to be overpowered by the PNS a bit so that you don't continue fighting needlessly. This is why when you have a fight with your girlfriend/boyfriend it is better to take a 10 minute break and go walk around alone for a minute than get into a car or room in close proximity. The SNS is still raging on and, many times, cause you or your partner to pick another fight.
In short, the SNS gets activated and takes a long time to settle down so that the PNS can take over and relax you for sleep.