He dropped out of the mayoral race and entered the campaign to become comptroller, the city’s chief financial officer and pension fund manager. All but uncontested, he seemed confident enough of victory that he began interviewing comptrollers around the country about their practices and printed custom campaign T-shirts for his sons, Max, 19 months, and Miles, 7 weeks, that read “Stringer Comptroller.”

“It was a nice moment,” Mr. Stringer said, recalling with relish how the tame campaign allowed him to spend time at home on the Upper West Side with his sons. “But now here we are.”

Mr. Stringer can now barely conceal his frustration with Mr. Spitzer, who jumped into the race four days before the deadline to qualify for the ballot without so much as a phone call to his opponent.

“I don’t hate him,” he said of Mr. Spitzer. “If he had bothered to call, I wouldn’t have hung up.”

Those close to Mr. Stringer variously describe Mr. Spitzer as a “nightmare” and “earthquake” for the Stringer campaign. Mr. Spitzer, whose family has a real estate fortune, can afford to finance his own campaign, and has a national reputation as a warrior against Wall Street from his tenure as the state’s attorney general.

“I feel badly Scott has to go through all this,” said Richard Ravitch, a former lieutenant governor of New York who has tutored Mr. Stringer on the intricacies of the comptroller’s office. “He will have to work much harder than he might have otherwise wanted to.”

In the days since Mr. Spitzer’s decision to challenge him, Mr. Stringer is moving swiftly to revamp his campaign. He hired a powerhouse political consulting firm, vowed to put together a potent team of field operatives to drum up votes and has started aggressively responding to Mr. Spitzer’s every move. (After learning that Mr. Spitzer would travel to Los Angeles on Friday to tape an appearance on Jay Leno’s show, a Stringer aide instantly criticized him for “skipping town four days into his campaign.”)