ROCKLAND, Maine — A South Thomaston man was sentenced Monday for robbing a Rockland pharmacy for drugs last summer.

Michael Willis, 29, was sentenced to seven years in jail with all but 21 months suspended. He was also placed on probation for three years.

The plea agreement was reached between the defense and the attorney general’s office. It also and had the blessing of the victim in the case — Curtis Jensen of Jensen Pharmacy.

Defense attorney Eric “Rick” Morse said Willis became addicted to painkillers after undergoing leg surgery.

Willis spoke before Justice Jeffrey Hjelm in Knox County Superior Court and apologized to Jensen as well as to his own family members for the suffering he caused them by the crime he committed.

“The drug addiction controlled me entirely. I put everything else on the back burner — honesty, trust, my wife, my son, my mother,” Willis said. “Thirteen months ago I reached the low point of my life.”

The robbery occurred July 31, 2012, at the pharmacy in the Breakwater Marketplace on Route 1 in Rockland. Police arrested Willis in January after clothing recovered near the pharmacy that had been identified as being worn by the robber was linked to Willis through DNA testing. Police reported at the time of the robbery that a man came into the pharmacy — wearing a fedora and sunglasses — and showed the pharmacist a note that said he needed 15- and 30-milligram oxycodone tablets. The note mentioned a gun.

Willis said he wanted to break the chain of addiction that has seen his father spend time in prison.

“I want to become the person I know I can be,” Willis said.

Willis spent five months at a residential rehabilitation center and additional time at a sober house in Portland. Morse noted that Willis began treatment before police had tied him to the crimes.

Justice Hjelm said he was accepting the plea, pointing out that the pharmacist was in support of the agreement. The judge said that robberies of pharmacies are prevalent and put everyone at risk. A condition of the probation is that Willis have no contact with Jensen Pharmacy and that if he does get prescriptions, they must be from one physician and filled at one pharmacy to prevent him seeking multiple prescriptions.

Jensen Pharmacy has been robbed twice in little more than a year. The store was also robbed earlier this month. Police arrested a suspect in the second robbery within hours.