Berkeley Rep hit upon “It Can’t Happen Here” about eight months ago, when an unexpected hole opened in its fall season. Lisa Peterson, who had signed on to direct a show for Berkeley Rep, Googled the phrase “it can’t happen here” and stumbled across the Sinclair Lewis novel, which she was not familiar with; Mr. Taccone had read the book in high school and thought it would work.

The novel is about a Vermont newspaper editor, Doremus Jessup, who opposes a demagogic presidential candidate, Berzelius Windrip; it is a satirical and melodramatic cautionary tale, in which Mr. Windrip wins the election, imposes martial law and seizes control of newspapers; his regime arrests and even kills his critics.

Lewis, who had already won the Nobel Prize for literature, wrote the novel against an ominous backdrop: Hitler and Mussolini were in power in Germany and Italy, and Huey Long, a senator and former governor who wielded unusual power in Louisiana, was preparing to run for the American presidency.

There are some striking similarities between the campaign pitches by the fictional Mr. Windrip and the real Mr. Trump — both men were even nominated for the presidency in Cleveland. But there are significant differences: Windrip, among other things, is a Democrat (in the novel, the Republican nominee winds up fleeing to Canada to plot a rebellion) and prone to warnings against Jews; Mr. Trump, of course, is a Republican who has focused his concern on Muslims.

In their new adaptation, Mr. Taccone and Mr. Cohen have sharpened the echoes. They wrote the campaign remarks by Windrip after watching stump speeches by Mr. Trump; they have one of their characters comment on the role of the news media (“The more offensive his remarks, the more papers get sold”); and, in a dig at Hillary Clinton’s reference to some Trump supporters as belonging to a “basket of deplorables,” a character explaining Windrip’s popularity says, “It’s not because they’re all stupid and prejudiced and deplorable.”

The novel was first adapted into a play and presented around the country in the late 1930s by the Federal Theater Project — Lewis himself appeared in one production, in Cohasset, Mass., as the journalist Jessup. But Berkeley Rep deemed that adaptation unrevivable (“it’s ghastly,” said Susan Medak, its managing director), so Mr. Taccone and Mr. Cohen, with the blessing of the Lewis estate, set about writing a new one in unusually short time.