Andrés Rivero was on a yearslong winning streak when he learned a personal lesson about “shades of gray” that made him walk away from gleaming prospects and a coveted job.

He knew it was time to leave his position as a federal prosecutor when he declined to pursue a perjury charge against a woman involved in a public corruption case.