CHARLOTTE, N.C. (AP) — The former mayor of North Carolina's largest city on Tuesday was sentenced to almost four years in prison for taking bribes from undercover federal agents he thought were developers seeking to fast-track projects.

Patrick Cannon had resigned in the midst of the case that stunned Charlotte residents who had once elected him as their youngest councilman. U.S. District Judge Frank Whitney in a courtroom just blocks from Cannon's old office sentenced the 47-year-old to 44 months. He also fined Cannon $10,000.

"You have seriously tarnished the city's image," Whitney said, adding "this court must send a message that public corruption is unacceptable and will be severely punished."

Cannon apologized for his wrongdoing.

"I have failed as a father, I have failed as a husband, I failed as a servant leader, and I failed as a citizen," Cannon told the judge before he was sentenced.

He said he knows how much he has hurt his family and community, which is why he decided to cooperate from the beginning.

As he walked out of the courthouse, he said, "Hopefully, the community will be forgiving."

In a deal with prosecutors, Cannon pleaded guilty in June to one count of honest services wire fraud. Prosecutors say Cannon accepted nearly $50,000 in bribes between January 2013, when he was a city councilman, and February 2014 — three months after he was elected mayor.

Cannon was arrested March 26 and resigned the same day.

He was elected to the city council in 1993 at 26, becoming the youngest member in Charlotte history. He was elected mayor in November 2013.

"I think the sentence is a very strong sentence that will send a message of deterrence," U.S. Attorney Anne Tompkins told reporters outside the courthouse.

His arrest shocked many who had worked with him and rocked a city that has prided itself on clean government.

The investigation began in 2010, after a tip from a local undercover officer about public corruption.

According to the criminal complaint, Cannon was recorded accepting more than $48,000 in cash, airline tickets, a hotel room and the use of a luxury apartment from FBI agents posing as real estate developers who wanted expedited permitting and zoning approvals. Cannon also was accused of soliciting up to $1 million in additional bribes from the undercover agents.

The conviction had carried a possible sentence of up to 20 years in prison and a $250,000 fine. During sentencing, Cannon's attorneys argued for leniency and recounted how their client pulled himself up from the inner city and devoted his life to public service.

When he was 5, Cannon's father was found dead of a gunshot wound outside a vacant school. Cannon was raised by his mother, who worked on a truck assembly line. They lived in public housing projects.

After high school, Cannon earned a degree in communications from North Carolina A&T State University.

As a young man, Cannon's confidence and ambition caught the attention of some of the city's biggest power brokers, including former mayor and current Gov. Pat McCrory. Cannon used those political and social connections to build a business managing 25,000 parking spaces, most in the city's central business district.

His attorneys said Cannon never forgot his roots, always helping people in trouble.

"He devoted himself to helping other people. That's what drove him into public life," said James Ferguson, one of Cannon's lawyers.

Two witnesses said Cannon was a doting father who always attended his two children's school events.

His attorney Henderson Hill said Cannon is still "struggling to understand" how he "fell into this conduct."

Cannon didn't elaborate on why he took the money. But he said when he thinks about it, he is "appalled" by his action, saying he has brought shame to his family and the city.

"I have repented and asked God for forgiveness," he said.

Whitney said that this is "tragic day" for Cannon, noting how far the former mayor had fallen. He noted that Cannon was a "lucky man" because he was surrounded in court by family and friends, and more than 30 people sent the judge letters praising Cannon's character. And he didn't doubt Cannon's remorse.

He also agreed with prosecutors and Cannon's lawyers that the former mayor saved the city a lot of potential strife by quickly resigning and cooperating with authorities.

But Whitney said there was no excuse for Cannon's behavior.

With his backstory, Cannon was "arguably Charlotte's model citizen." But along the way, he succumbed to "raw greed."