Tim Sini, the Democratic police commissioner in Suffolk County, scored a resounding victory in the race for district attorney there on Tuesday, convincing voters that he would clean up the corruption engulfing the county’s law enforcement agency.

It was only three weeks ago that the sitting district attorney, Thomas J. Spota, a Democrat, was indicted on charges of witness tampering and obstructing a federal investigation. Mr. Sini managed to distance himself from his fellow Democrat and convey his success in ridding the county’s police department of similar corruption.

“Together we have ushered in a new era of criminal justice in Suffolk County, an era of integrity, fairness and doing the right thing,” Mr. Sini said in a victory speech just before 11 p.m. “We are going to return the office to the honorable institution that it once was.”

Mr. Sini received 62 percent of the vote, with 92 percent of electronic ballot scanners counted. In defeating his Republican opponent, Ray Perini, a veteran defense lawyer and former prosecutor, Mr. Sini overcame the political math in a county that had voted for President Trump. Last November, Mr. Trump received 50,000 more votes in Suffolk County than did his opponent, Hillary Clinton — an eight-point margin in a county that had voted for Barack Obama in both of his presidential elections.