REUTERS/Ng Han Guan/Pool
The 64-year-old became the first ethnic Chinese in the post when he was appointed in 2011, going on to gain quasi-celebrity status for his modest style and for drawing attention to China's unhealthy skies.
But Locke, who left his role on Saturday, received a highly undiplomatic sendoff from the China News Service in a sneering editorial which referred to him as a "banana", and a "guide dog" for helping a blind activist.
"He is a banana with yellow skin and a white heart", Friday's article opened by saying, calling Locke's ethnicity a ploy by the US to win Chinese hearts and minds while seeking to kick up trouble in the region.
"But the 'yellow skin' of bananas will eventually rot, not only revealing the 'white core' inside but also turning into a putrid 'black core'," the commentary went on.
Locke was viewed as a trailblazer in highlighting the PM 2.5 particulate matter carried in the thick blankets of smog pervading China's capital.
He presided over the introduction of PM 2.5 monitors at the US embassy and consulates around China, drawing widespread attention to the stubborn problem of pollution.
But the official agency wrote that "once Locke arrived, so did the Beijing smog".
It also scorned Locke's image as an unpretentious official known for carrying his own luggage and using a regular car in contrast to his Chinese counterparts.
Citing unnamed foreign media outlets, the commentary accused him of luxuriating in a $100 million official residence and traveling in a fancy bullet-proof vehicle.
The verbal attacks didn't stop there with the editorial deriding him as a "guide dog" for assisting the blind activist Chen Guangcheng in 2012.
Chen sought shelter in the US embassy after escaping house arrest in nearby Shandong province before being allowed to go to America with his family.
Many Chinese social media users criticized the essay and defended Locke.
"He took concrete steps to show us what our officials are really like. He taught Chinese people about PM 2.5 and the truth behind it... and ultimately spurred the Chinese government to confront the issue of smog," said the writer Guo Jingming.
Another commentator rejected the essay as "a breach of truth, breach of logic, breach of ethics, breach of civilized behavior and breach of diplomatic etiquette, and makes it hard to believe this country has thousands of years of civilization".
In a farewell press conference on Thursday Locke highlighted the embassy's role in raising awareness about air quality, among other accomplishments, and urged China to improve its human rights record.
He described himself as "proud of my Chinese heritage" but also "thoroughly American" and "proud of the great values that America has brought to the entire world".
Chinese foreign ministry spokeswoman Hua Chunying gave a more measured response on Locke's tenure, saying this week he had "made some positive contributions to cooperation between China and the US".