Michael Cohen appeared in court on Wednesday to be sentenced by US District Judge William H. Pauley III for an array of crimes he committed while employed by President Donald Trump.

Cohen was sentenced to 36 months in prison.

Cohen lied to Congress about his involvement in a plan to build a Trump Tower in Moscow and made hush-money payments in 2016 to two women who said they had affairs with the president.

Cohen had asked the judge for no prison time, saying he has tried to be cooperative.

Michael Cohen was sentenced to 36 months in prison on Wednesday by US District Judge William H. Pauley III for an array of crimes he committed while employed by President Donald Trump.

Cohen, who was Trump's longtime lawyer, apologized for his actions and said he acted out of "blind loyalty" to Trump.

"Recently, the president tweeted a statement calling me weak, and it was correct, but for a much different reason than he was implying: It was because time and time again I felt it was my duty to cover up his dirty deeds," Cohen told the court, adding that he took "full responsibility" for his crimes.

"Today is the day that I am getting my freedom back," Cohen said, adding, "I have been living in a personal and mental incarceration ever since the day that I accepted the offer to work for a real-estate mogul whose business acumen that I deeply admired."

Cohen had asked the judge for no prison time, saying he has tried to be cooperative.

His lawyer, Guy Petrillo, said during Wednesday's sentencing that Cohen had come forward "to offer evidence against the most powerful person in our country."

But Pauley said Cohen's cooperation "does not wipe the slate clean."

"Each of these crimes standing alone warrant considerable punishment," Pauley said, adding that Cohen "thrived on his access to wealthy and powerful people, and he became one himself."

"Somewhere along the way, Mr. Cohen appears to have lost his moral compass," the judge said. "As a lawyer, Mr. Cohen should have known better."

Pauley said Cohen was guilty of a "smorgasbord of fraudulent conduct."

Assistant US Attorney Nicolas Roos on Wednesday said Cohen's crimes revealed a "pattern of deception, of brazenness, and of greed."

Roos accused Cohen of harming the interests of "free and transparent elections" and eroding "faith in the electoral process."

Cohen has implicated Trump in multiple felonies

Cohen lied to Congress about his involvement in a plan to build a Trump Tower in Moscow and made hush-money payments in 2016 to two women who said they had affairs with the president.

Read more: Trump has been implicated in several federal crimes, but here's why experts say he hasn't faced legal consequences

The president's former lawyer pleaded guilty in August to eight federal crimes, including tax fraud, bank fraud, and campaign-finance violations.

Cohen implicated Trump in the campaign-finance violations, which were connected to the payments, saying they were made on the president's behalf at the height of the 2016 campaign. More recently, Cohen pleaded guilty to lying to Congress about the Trump Tower project in Moscow.

Federal prosecutors for the Southern District of New York released a sentencing memo last Friday recommending Cohen receive 3 1/2 years in prison and pay a $100,000 fine. The prosecutors said Cohen "deceived the voting public by hiding alleged facts that he believed would have had a substantial effect on the election."

Read more: Federal prosecutors recommend a 3.5-year sentence for former Trump lawyer Michael Cohen

"With respect to both payments, Cohen acted with the intent to influence the 2016 presidential election," the filing said. "Cohen coordinated his actions with one or more members of the campaign, including through meetings and phone calls, about the fact, nature, and timing of the payments ... And as Cohen himself has now admitted, with respect to both payments, he acted in coordination with and at the direction of Individual-1."

Individual-1 is Trump, who has shifted from denying having any knowledge of the payments to characterizing them as a "simple private transaction."

Robert Mueller, the special counsel leading an investigation into Russia's election interference, also released a sentencing memo on Friday. Mueller recommended Cohen receive a sentence reflecting that lying to federal investigators has serious consequences, but he also called for "due consideration" to be given to Cohen's cooperation with his probe.

Trump, who once had a close relationship with Cohen, has called his former personal lawyer a liar and in a recent tweet said he should receive a "full and complete sentence."

Cohen, who in September 2017 said he would "take a bullet" for Trump, said on Wednesday that his loyalty to the president was what led him to go down "a path of darkness instead of light."

Cohen's legal team on Wednesday said he planned to continue to cooperate. Lanny Davis, an adviser to Cohen, said the president's former lawyer would "state publicly all he knows" about Trump after Mueller completes his investigation. Davis said this could include testifying before Congress.

"Mr. Trump's repeated lies cannot contradict stubborn facts," Davis said in a statement.

Read more: Here's a glimpse at Trump's decadeslong history of business ties to Russia