Moments before embattled rap artist Meek Mill stepped out of a Philadelphia courtroom free of any parole or probation for the first time in more than a decade, the judge overseeing his case offered words of caution.

"You know right from wrong. You know up from down. You know what to do. Don't be persuaded by anyone but yourself," Philadelphia Court of Common Pleas Judge Leon Tucker said. "Don't deviate from the path you're walking."

Mill, whose real name is Robert Rihmeek Williams, agreed to plead guilty to a first-degree misdemeanor offense of carrying a firearm. The offense carries a sentence of up to five years in prison and a fine of as much as $10,000, but the Philadelphia District Attorney's Office had agreed that Williams deserved no further punishment.

During a roughly 30-minute hearing Tuesday morning, the parties outlined the agreements, and Tucker accepted the plea deal, which ends a legal saga of more than a decade that stirred the Philadelphia legal community and helped fuel a national conversation about the criminal justice system.

"I know it's been a long road for you, and hopefully this will be the end of it," Tucker said, after accepting the plea.

Williams has been on probation since 2008 after he was convicted on drug- and gun-related charges. The case, however, caught national attention after the judge who initially handled his case, Philadelphia Judge Genece Brinkley, sentenced the hip-hop star to a two- to four-year prison sentence for a probation violation in November 2017. The sentence staggered the rapper's supporters, since neither the probation officer nor the prosecutor on the case had sought jail time, and eventually the sentence garnered national attention.

During the protracted appeals process, the case spurred hundreds of additional appeals involving cases handled by the arresting officer and led one court employee to be fired. The pleadings also raised a cloud over Brinkley's role in the matter. While Brinkley was removed from the case by the appeals court, she was not charged with wrongdoing.

After some newly discovered evidence came to light casting doubts about the credibility of Williams' arresting officer, who was the only witness at the trial, Williams redirected his appeal from focusing on the legality of the sentence to seeking to have the initial conviction vacated.

Although Brinkley, who handled his initial trial, denied those efforts in June 2018, the Superior Court in July granted Williams a new trial and tossed Brinkley from the case.

Questions, however, lingered about whether the Philadelphia District Attorney's Office would continue to pursue charges against Williams or simply drop the case.

Assistant District Attorney Paul George, who appeared on behalf of the prosecution during Tuesday's hearing, noted that Williams had no prior or subsequent convictions following his initial conviction and that Williams was successfully employed, which, George said, is a goal of parole and probation. Those factors, along with Williams admitting he carried a gun during the 2007 incident for which he was initially convicted, led prosecutors to agree to the deal, according to George.

"In view of the unique history of this case, all of the charges will be dropped and the commonwealth will not ask for a further penalty," George said.

Williams' attorney, Joe Tacopina of Manhattan, noted the rapper's recent philanthropic work, including donating to local schools, hosting a jobs fair, and helping found Reform Alliance, a nonprofit aimed at criminal justice reform.

Williams said little during the hearing, except to answer Tucker's questions about his understanding of the deal, his level of education and his satisfaction with his legal counsel.

After the plea deal was accepted and entered, Tucker noted that Strawberry Mansion High School—the school from which Williams said he dropped out—was the same school Tucker had graduated from decades before. Williams, Tucker said, was now a representative of the community.

"The court simply asks that you continue to do the good things you do recently," Tucker said. "People depend on you."

Moments later, Williams left the courtroom a free man.