Umm it can be very confusing and there is a lot of debate over what happened exactly at the ending, if you do a google search I'm sure if you can find one of them.
From what I take it though many believe it is more on the lines of the world changing into another version caused by the other world with the robot thing and Girl.
I believe the world changed, and only Tomoya remembers the events from the other world. How exactly did it change and why? I'm not too sure of that myself and last time I watched it was a long time ago. So yeah google it and read or join in one of the long discussions about it if you want more details, or different takes on it.