Five other Pakistani men, some of whom were under 18 at the time of their crimes, were jailed for between three and 12 years on terror conspiracy charges for supporting Mahmood.
The trial was held at the Juvenile Court in Paris because of their centuries.
The court heard Mahmoud planned his attack after Charlie Hebda republished his cartoons of the prophet in September 2020 to mark the opening of the trial of some of those responsible for the 2015 massacre.
The court was told that Mahmud was under the influence of radical Pakistani preacher Khadim Hussain Rizvi, who urged him to “take revenge on the prophet”.
Armed with meat, he arrived at Hebd’s former offices in France’s 11th arrondissement and also seriously injured two employees of the premier Lignes agency, which has offices nearby.
Witnesses at the time told how they saw their colleagues “bloodied, being chased by a man with a machete”.
His victims, a woman named “Helen”, 32, and a 37-year-old man, attended the sentencing but would not comment on the outcome.
None of them accepted Mahmoud’s plea for forgiveness.
“It broke something in me,” said the 37-year-old guy, speaking in court about the long rehabilitation process.
Mahmoud arrived in France illegally in 2017, although he initially claimed to have arrived in 2019. He also lied about his age, saying he was 18.
Mahmoud’s defense lawyer, Albert de Heydon, said his client lived and worked with Pakistanis and felt cut off from France.
“He doesn’t speak French, lives with Pakistanis, works for Pakistanis,” Mr Gaydon added. “He never left Pakistan in his mind.”