AUBURN, Maine — A 77-year-old Greene man agreed to plead guilty to a misdemeanor charge related to an incident in a Walmart parking lot last summer in which the defendant threatened to hit a Sabattus man with a baseball bat and spewed racial epithets.

Keith Clayton Hanning, 77, of 146 Sedgley Road, will be allowed to withdraw Monday’s plea in a year and plead to a lesser charge in Androscoggin County Superior Court if he stays on the right side of the law.

Hanning pleaded guilty to criminal threatening, a Class D misdemeanor punishable by up to 364 days in jail. If Hanning complies with the terms of his plea and doesn’t engage in criminal conduct, he’ll be allowed to withdraw that charge this time next year and plead instead to disorderly conduct, a Class E misdemeanor. He won’t face a fine or jail time, but the charge will remain on his criminal record.

Hanning must engage in mental health counseling with a focus on anger, violence and racial sensitivity issues as a term of the agreement. He must receive evaluations every three months starting in January.

Meanwhile, state prosecutors filed a civil complaint against Hanning under the Maine Civil Rights Act seeking an injunction that would bar him from having any contact with the victim or his family. A hearing had been scheduled for early December on the state’s motion for a preliminary injunction, but Assistant Attorney General Leanne Robbin said Monday that Hanning has indicated his willingness to sign a consent order for a permanent injunction, making the need for a hearing unnecessary.

Police said Hanning was in the parking lot of the Auburn Walmart store on July 23 when a car pulled into a parking space and ran over the curb that bordered the parking space and median walkway in which Hanning had been walking.

Hanning yelled at the passenger, Tyrone Davis, who apologized to Hanning for the driver’s error, according to court papers. The driver of the car, whose foot was encased in a support boot due to an earlier injury, got out of the car and apologized to Hanning.

As Davis began to explain why the driver had difficulty maneuvering the car, Hanning said, “Go back to Africa” and called Davis a “n——-” and said he would kick (Davis’) ass,” according to court papers.

Davis was holding the couple’s 2-year-old daughter in his arms during the confrontation. An infant son remained with his mother, who was white.

Hanning pushed Davis, then crossed the parking lot to his vehicle, where he retrieved a baseball bat and turned to Davis and his family, brandishing the bat, according to police.

Davis put down his daughter and walked to Hanning in an effort to keep him from coming near his children and their mother, police said.

Hanning threatened to hit Davis with the bat, prompting a number of witnesses to call 911, police said.

If Hanning signs a consent order for an injunction and he were to violate its terms, he could be charged with a Class D crime.