PUTNAM COUNTY, Fla. -

After four days of trial testimony, a 21-year-old man abruptly entered a guilty plea to charges of second-degree murder and attempted first-degree murder, just before the beginning of closing arguments Thursday.

Each charge against Avery Corbitt carries a potential sentence of life in prison.

Prosecutors said Corbitt offered to sell drugs and guns to undercover officers in April 2011, when, in fact, he and his accomplices planned to rob the officers. At the scene of the intended robbery, Corbitt and his accomplices drew guns on the undercover officers, and an exchange of gunfire ensued, killing Corbitt's accomplice, 23-year-old Rodrigo Espinoza, and seriously wounding St. Augustine Beach Detective David Tiller.

Under Florida law, Corbitt was guilty of second-degree murder for the death of his accomplice, and attempted first-degree murder for shooting the undercover officer.

A third suspect, 17-year-old Emmanuel Espinoza, fled the scene and was arrested after a two-hour manhunt.

"The danger our law enforcement officers face performing their duties became a reality that day, but justice has prevailed and thankfully the officer has recovered," State Attorney R.J. Larizza said in a news release.