Bill de Blasio, completing a stunning political turnaround, assumed the role of standard-bearer of New York City’s Democratic Party on Monday, as his last remaining primary rival exited the mayoral race and he turned his attention to a fight against a Republican opponent with a starkly different vision.

In a coronation of sorts on the steps of City Hall, the state’s Democratic leaders, eager to retake the mayor’s office after almost two decades out of power, feted Mr. de Blasio as a bold new messenger for their party — even as they praised William C. Thompson Jr., the second-place primary finisher who had held out nearly a week before announcing his withdrawal.

“There is nothing more beautiful than Democratic unity, and thank you for it,” a beaming Mr. de Blasio said, as Mr. Thompson, his face frozen in a smile, stood behind him.

It was a triumphant moment for Mr. de Blasio, until recently a little-known liberal, who overcame doubts from many Democrats about his candidacy. But he almost immediately faced sharp attacks from the Republican nominee, Joseph J. Lhota, who held his own event on Monday and denounced Mr. de Blasio’s left-leaning platform as extreme.