With the election only about a week away, New York City Mayor Bill de Blasio was supposed to be preparing for his final debate. Instead, the Democrat was addressing the nation on national television, shoulder-to-shoulder with the governor and the police commissioner, as the city grappled with a deadly terror attack.

"This was an act of terror, and a particularly cowardly act of terror," a solemn de Blasio declared less than a day after a man driving a pickup truck killed eight people on a Manhattan bike path. "We know this action was intended to break our spirit. But we also know New Yorkers are strong, New Yorkers are resilient and our spirit will never be moved by an act of violence."

It was not a moment the first-term Democrat wanted, but one that colors the final-days sprint to Tuesday's election.

Facing little more than token opposition, de Blasio is still expected to cruise to victory. But the attack highlights his complicated relationships with Democratic New York Gov. Andrew Cuomo and Republican President Donald Trump — relationships that may be moving in opposite directions as he moves closer to securing a second term as chief executive of America's largest city.

In a city where Democrats outnumber Republicans 6 to 1, de Blasio has lashed out at Trump with increasingly frequency as Election Day approaches. On the eve of the attack, he vowed to "stand up to Donald Trump every single day" during a campaign rally in which he and Vermont Sen. Bernie Sanders, an independent, took turns bashing the Trump White House. He softened his tone only briefly in the hours after the attack, jabbing the president without using his name for calling for a crackdown on some legal immigration in the wake of the New York City attack.

Like most elected officials in blue states, the mayor has long opposed Trump's push to ban on immigration from several majority-Muslim nations.

"There should be very, very careful vetting of anyone where there is an indication of a concern, but not because of their religion, or not because of their country of origin," the 56-year-old de Blasio said.

The mayor's leadership in the days after the attack, and his repeated attacks against Trump, bother independent mayoral candidate Bo Dietl, 66, a former police detective. The New York City mayor needs to have a good relationship with the president, Dietl said, to ensure the White House doesn't retaliate by withholding federal funding for public safety.

"This man is such a nonsensical idiot. He can't even sit down with the president. That means for the next four years we're not going to get federal money for our cops?" Dietl said in an interview. "This terrorist attack really made people re-look at this and say, 'Do we really want a big bird to protect us?'"

At the same time, de Blasio's turbulent relationship with Cuomo showed mild signs of improvement.

Despite both being Democrats, Cuomo has jabbed de Blasio's leadership and policies for much of his first term. The clash is a political distraction at best, and at worst, an impediment to governance in a city in which the state government plays a significant role in public transportation and education, among other areas.

A week before the attack, Cuomo seized on a photo of a homeless man sleeping on the subway to ding the mayor. De Blasio press conferences often feature multiple questions about the feud.

"It's no secret that there's no great love lost between the two of them — two alpha male politicians in powerful positions," said Bill Bratton, the city police commissioner under de Blasio until 2016. "They have to work together. Sometimes they do and sometimes they don't."

Bratton added, "But in moments of crisis, those political differences are put aside for the public good."

Indeed, Cuomo and de Blasio stood side-by-side in the days after the attack, united in their condemnation of terrorism and Trump's decision to blame Democrats' immigration policies for the violence less than 24 hours after the attack. Whether the spirit of cooperation will continue between the New York Democrats is an open question.

Republican candidate, 36-year-old state assemblywoman Nicole Malliotakis, vowed to improve the mayor's relationship with the state and federal government if elected.

"We're going to work with our partners in government to get the resources we need in our city," she said during a press conference this week as she accepted an endorsement from the MTA's police union. "I feel that people have just had it with Bill de Blasio."