Democratic leaders’ scheme to “cut the head off the IDC snake” was not forged in a dark alleyway or an Italian restaurant, but over egg whites.

It was May 2017 when Democratic powerbroker Sen. Michael Gianaris secretly arranged to meet a new recruit, a young lawyer in the governor’s office named Alessandra Biaggi. Outside both their native boroughs, they met early one Friday morning at an Upper West Side cafe. Gianaris was there to see if Biaggi was the one who could depose his rival, fellow Democrat Jeff Klein, who had allied with the Republicans for years. The clandestine breakfast was only one part of an ambitious strategy to oust Republican-aligned Democrats and wipe out GOP incumbents to wrest control of state legislature.

And despite all historical precedent to the contrary, the plan worked.

New York Democrats achieved a remarkable margin of victory in the New York state senate, locking in 39 of 63 seats. That has left them firmly in control of the legislative and executive branches of New York government with the power to pass progressive laws long-stalled by state senate Republicans and their allies.

The results were not simply the result of a “blue wave,” party leaders say. If State Senate Democrats had won by similar margins as Democrats running for statewide or federal offices, one could chalk that up to that a wave election, but that’s not what happened. In several cases, New York voters overwhelmingly chose a Democratic state senate candidate, while rejecting Gov. Andrew Cuomo or a Democratic congressional candidate.

In the Hudson Valley, voters chose a Republican for governor but also Democrats James Skoufis and Jen Metzger, who outperformed Cuomo by six and seven percentage points, respectively. On Long Island, both Monica Martinez and John Brooks outperformed congressional challenger Liuba Grechen Shirley by three points a piece.

Senate Democrats credit their victories to a carefully-crafted playbook, a secret anti-IDC recruitment drive, and alliances with ascendant grassroots groups; all of which boosted their ballot tallies on Election Day.

After decades of near-complete Republican control of the State Senate, Democrats now hold the largest share of seats in the state’s upper house since 1912—a time when a 30-year-old Franklin Delano Roosevelt sat in the State Senate, the latest tech was Ford’s Model T automobile, the political outrage of the past year was the Triangle Shirtwaist garment factory fire, and women had no right to vote.

The new 39-to-24 majority marks a pivotal political shift. But while voters clearly expressed a broad preference for Democrats, State Senate Democrats ran up the score and outflanked their rivals in surprising ways—plotting to depose fellow Democrats and targeting popular Republicans previously thought safe.

If they were once shy about their methods, that time is over.

“We totally wiped the floor with the Republicans all over the state,” said state Senator Michael Gianaris, chair of the Democratic Senate Campaign Committee who quarterbacked his party’s election strategy.

In a series of interviews, state Senate strategists shared once-secret party research documents with Gothamist, attributing their wins to incisive data analysis and shrewd campaign strategy that was matched with a robust ground game thanks in large part to energetic candidates and thousands of Democratic volunteers who drove voters to the polls.

Still, there’s an uneasy familiarity to this victory—Democrats have bungled a majority before. In 2008, state senate Democrats won a slim 32-30 majority in the state senate that quickly slipped away during an embarrassing leadership crisis, marked by infighting. Forty years earlier, in 1964, another Democratic majority was also quickly undone by factionalism.

This year will be different, Gianaris said. He has played the long game, laying the groundwork since he arrived in the State Senate.

“It’s safe to say, in 2010 things were at a low point,” Gianaris said. Republicans had flipped several seats after the crisis of 2009 and retaken the chamber. On Jeff Klein’s watch, the party had not only lost seats but accumulated $3 million in debt. Klein, an ambitious Democratic senator from the Bronx who had directed party strategy, was stripped of his title and resigned his leadership position, but blamed other party leaders for the election losses. Within months, Klein formed a group of breakaway Democrats, the Independent Democratic Conference, that would ally with the Republican majority for the next seven years.

Gianaris inherited Klein’s post, the party’s debt, and minority party status.

“The Democrats had just lost the majority. The IDC was just established. Things were somewhat of a mess,” Gianaris said. For years, the Republican-IDC coalition, joined by Democratic Party heretic Simcha Felder, locked Democrats out of power, despite a numerical majority of registered Democrats.

But in 2016, Donald Trump’s election shocked the political system, changing the state’s political topography. A grassroots anti-Trump resistance movement injected first-time activists into local politics, and Democratic party leaders began to believe that the 2018 elections could be a good year if they could harness and direct that energy.

But first, Gianaris had to take care of some unfinished business within his own ranks. He began secretly recruiting candidates to knock out the IDC rebels who had deprived the mainline Democrats of power for years.

When Gianaris first recruited Biaggi, she knew that Senate Democrats were fed up with the IDC leader but also that Democrats rarely attacked their own.

“Traditionally, Democrats don’t primary other Democrats. It’s not a thing that happens,” Biaggi said. "There’s this code of silence that they all take with each other that it doesn’t matter if you’re a bad apple, we’re still going to get behind you.”

But Gianaris was throwing that rule book out the window. “We were trying to convince her” to challenge Klein, he said of Biaggi. “She was definitely interested but had not made a final decision.”

To encourage her, Gianaris passed her research and analysis that amounted to a political playbook, as reported last year. That playbook laid out a battle plan showing where and how Klein could be beaten—if she could win big in Riverdale and rally young voters, a female candidate could win. Klein was “formidable, but vulnerable.”

Gianaris said he also recruited others to depose IDC members, including Jessica Ramos, Zellnor Myrie, Robert Jackson, and John Liu—all of whom ultimately succeeded in their mission to oust IDC members.

“We were engaged in a very vigorous effort to recruit and help these people along, up until the governor got involved and made the deal that required us all to stand down,” Gianaris said.

Cuomo’s unity deal with the IDC dissolved the GOP-allied faction under the promise that the Democratic Party would not support primary challenges against IDC members. Communication between Albany Democrats and the chosen challengers went dark.

But Gianaris already had his candidates in the field, acting on intelligence he provided. “By that point it was so late in the game that candidates were off on their own,” Gianaris said. “In other words, we got them off the ground and it was too late to stop them!” he said with a laugh. “Not that we tried.”

By all accounts, the candidates did the heavy lifting after that. Working late nights, knocking thousands of doors, and wearing out several pairs of shoes, Biaggi credits that legwork to her victory over Klein. “It’s remarkable that we were able to pull this off considering the incredibly small amount of support that we had from the beginning,” Biaggi said. “I am a hustler and I out-hustled him.”

Funding dollars also started rolling in early, with discussion of a “blue wave” in 2017 after Democrats flipped both the Westchester and Nassau County executive seats and five Republican senators retired. That had a multiplier effect, Gianaris said. “The donor class took a look and realized that this is really happening for us,” Gianaris said. The Democratic Senate Campaign Committee alone was able to spend about $5.5 million. “There was a real vigorous and well-funded campaign effort around the state the likes of which we’ve never seen.”

The committee ended up funding nine races around the state, when typically it would only fund three or four. They spread the money out, giving just enough to allow candidates to eke out a win and allowing grassroots enthusiasm to carry other candidates. “We funded what we knew we had to fund,” Gianaris said.

That money was spent particularly well online.

“Digital played a huge role in our campaign,” a Senate Democratic strategist told Gothamist. Online political ads on Facebook and elsewhere were more nimble and targeted, he said. “We spent more on digital that we ever had in the past. It was essential.”

As Democrats geared up for the general election, in addition to money and grassroots allies, they were armed with a set of insights gleaned from their analysts, previously unpublished internal research shows. Senate strategists examining election data spotted three critical trends that would form the backbone of their strategy and show them which battles to fight.

A chart from State Senate Democrats' internal research analysis preceding the midterm elections.

“We had noticed in 2016 as Trump was being elected that there had been this realignment,” the strategist explained. “College-educated voters jumping over to Democrats. And voters without college education, even if they were registered Democrats or had voted Democrat in the past, moving over to the Republican side and voting for Trump. So when we were looking at our opportunities in 2018, we were looking at the suburbs and places that had higher levels of education, that were more diverse.”

Senator-elect Anna Kaplan’s newly-won district just east of Queens is a case in point—“where she just beat Elaine Phillips is both super educated and very diverse.”

“So we first looked at districts that seemed to be demographically advantageous to us,” the strategist said. “Then, we also started seeing throughout the last two years a decrease in ticket splitters.” In other words, Democrats and Republicans would more reliably vote for their party.

This put districts where Democrats had a numerical enrollment advantage in the crosshairs, even if Republicans had won Democrats’ votes in the past. State Senator Marty Golden was at the top of that hit list. His district showed a 28 percentage point enrollment advantage for liberals.

“He had gotten Democratic votes for such a long time that people assumed that it was a forgone conclusion,” the strategist said, but Andrew Gounardes's victory would prove otherwise.

The third insight was that so-called “Obama-Trump” districts, where both those presidents prevailed, a superior or unique candidate, like James Skoufis or Jen Metzger, could pull off a win.

In several races, candidates’ focus was often far from national or even statewide politics.

In Long Island, Democrats hammered Republican candidates on corruption in local machine politics. Jim Gaughran, in particular, drilled down on water.

“It’s not a sexy issue, but people there care about their water rates,” the strategist said.

As much as the midterm election has been cast as an anti-Trump uprising, for individual state senate candidates, it was not a central focus. When it was convenient, they might call out the president, but often it was not. For several candidates, they needed Trump loyalists to vote for them.

“I carried some very Republican election districts,” Gaughran said, noting that those were important votes for him to win. “You also had to get people who supported Donald Trump to vote for you. We did.”