William Bratton, with a warm grin and accompanied by his wife, Rikki Klieman, walked out of police headquarters Friday for the final time as NYPD commissioner, capping a festive day marking another transition of power at the nation’s largest police force.

The long, leisurely traditional “walkout” — as the event is known in police circles — occurred about 3 p.m., shortly after Bratton’s successor James P. O’Neill was sworn in as commissioner by Mayor Bill de Blasio in a private ceremony. A public swearing-in will take place on Monday.

Bratton, 68, left the job as the city’s 42nd police commissioner to take a position with Teneo Holdings, a private global consulting firm based in New York. Bratton took over a department in crisis — slammed by critics over an aggressive stop-and-frisk policy and accusations of using excessive force.

O’Neill, 59, had been Bratton’s chief of department, the highest-ranking uniformed officer. Carlos Gomez, 53, of Suffolk County, assumes O’Neill’s former post after having served as chief of patrol.

At the end of the walk, within earshot of a small group of protesters, Bratton and his wife were embraced by de Blasio and Klieman was given a bouquet of two dozen yellow roses. Then, with the assistance of Lt. Tony Giorgio, the couple stepped into a 1930 Mack emergency service police vehicle for a short ride under the arch of the David Dinkins Municipal Building. The vehicle took them a short distance near City Hall, where they got into their own car.

In the hours before relinquishing a job he loved, Bratton met scores of well wishers, headquarters staffers, politicians and other law enforcement officials in a series of impromptu receptions. Present among them were Gomez, his wife, Lisa, and their daughters, Jenna and Danielle. Bratton then addressed a crowd of hundreds inside the headquarters auditorium.

advertisement | advertise on newsday

“No police organization in the world has the capabilities or the will or the capacity of the NYPD,” Bratton told the throng.

“There is a reason the NYPD is called the finest. It is not an idle boast. It is because it is what we do. Thank you,” Bratton said to applause.

In two poignant moments, Bratton had the crowd applaud the families of officers who had died during his second stint as commissioner and then got more applause when he thanked his wife, a television legal commentator, for sacrifices she made so he could realize his career ambitions.

“I want to thank you for that,” Bratton said to his wife, his voice quivering.

De Blasio said in a WNYC-FM interview Friday morning that Bratton has his gratitude and respect.

“He did more than anyone in the history of the city to make this city safer,” the mayor said, “and also did more to reform police practices and create an opportunity for police and community to come together.”

Gov. Andrew M. Cuomo on Friday praised Bratton’s tenure as police commissioner, which Cuomo said “is probably the most important job in New York City government.”

Cuomo said Bratton brought confidence to city residents: “You said, ‘I can sleep well tonight, Bratton is on the case.’”

advertisement | advertise on newsday

Bratton and O’Neill were actually on the case Thursday night when they responded to an incident in midtown in which cops fired upon a man who allegedly attacked them with a hatchet. Both men then took a final patrol in the subway — both had been transit cops at one time — but didn’t need to make any arrests.

“Not even a fare evader,” quipped Bratton.

With Emily Ngo and Michael Gormley