The result is “Agency,” Mr. Gibson’s next novel, which Berkley will publish in January. The story unfolds in two timelines: San Francisco in 2017, in an alternate time track where Hillary Clinton won the election and Mr. Trump’s political ambitions were thwarted, and London in the 22nd century, after decades of cataclysmic events have killed 80 percent of humanity. In the present-day San Francisco setting, a shadowy start-up hires a young woman named Verity to test a new product: a “cross-platform personal avatar” that was developed by the military as a form of artificial intelligence. Meanwhile, characters in the distant future are interfering with the events unfolding in 2017, through technological time travel that allows them to send digital communications to the past.

For the most part, people living under President Clinton carry on as if nothing unusual has occurred. “The characters in the book are scarcely aware of the broader political landscape,” Mr. Gibson said. “No one ever says, ‘Thank God we’re not in that other time track.’”

In some ways, “Agency” functions as both a sequel and a prequel to Mr. Gibson’s noirish 2014 novel, “The Peripheral,”set partly in the same futuristic, postapocalyptic London, after the world has been devastated by climate change, droughts, famines and political chaos. The novel’s plot also hinges on technological time travel, which enables people from the future to alter past events and create a “stub,” or an alternate time track.

Mr. Gibson never set out to write a sequel, but the plots of “Agency” and “The Peripheral” converged unexpectedly last fall. He had spent about a year writing “Agency” when the 2016 election rendered the fictional world he had created obsolete. “I assumed that if Trump won, I’d be able to shift a few things and continue to tell my story,” he said. But when he tried tinkering with the draft, he realized that the world had changed too drastically for him to plausibly salvage the story. “It was immediately obvious to me that there had been some fundamental shift and I would have to rebuild the whole thing,” he said.

He changed the framework by resurrecting the time-travel mechanism he created in “The Peripheral” and making the world in which Mrs. Clinton won the presidency a stub, an alternate branch of reality created by a meddling time traveler.