Well it could be that when Nagisa was giving birth to Ushio, Tomoya thought that Nagisa died, adn in doing so created a series of events that he thought might've happened without Nagisa in his life. It became a series of events that would lead to his life being a big tragedy. The trigger was probably when Nagisa passed out and Tomoya started doubting himself and wondering if it was better that he didn't meet Nagisa.
But right after that Tomoya recollected his thoughts, and came to the realization that he couldn't have not met Nagisa in his life, because she completed him as a person. When Tomoya realized that, he came back to the real world, where Nagisa wasn't really dead, and woke up when Tomoya called out to her. This is me trying to interpret it in a realistic point of view.
Then there's the miracle interpretation, where Tomoya in given another chance thanks to Ushio from the other world. I like how they gave the series a happy ending, and I'm completely satisfied with how they did it.
I hope this helped you in some way.