Darwinia by
Robert Charles Wilson
*spoiler alert*
This novel starts out as a classic alternate history, where in 1912, most of Europe gets replaced by a topologically similar, but developmentally different Europe. The first half of this book is about a couple of people who have been contacted by ghosts of their alternate selves, and by evil bug things on a quest to take over the world.
Then, things start to get a little weird. It is revealed that this is not the real world at all, but a computer simulation in a galactic archive whose purpose is to preserve all sentient experience everywhere. The simulation has become infected by semi-sentient information viruses from a different reality, who want to have a real life of their own. They are bent on taking over the earth simulation, and eventually the rest of the archive.
Towards the end of the book, different characters undergo transformations and everything converges on the evil insect stronghold in the center of Darwinia, where a deep well leads into the center of their will and purpose, and where the fate of the archive, and the newly original world, hangs in the balance.