The man posted a picture of himself holding the baby out of a window in a high-rise building with the caption: "1,000 likes or I will drop him."
It prompted other social media users to demand his arrest for child abuse.
He was charged with endangering the baby's safety following his arrest on Sunday, police said.
The child was dangled out of the 15th-floor window of an apartment block in the capital, Algiers, news site Al Arabiya reported.
The man, who is a relative of the child, denied he put his life at risk, saying the image had been altered by social media users, Algeria's privately owned Ennahar TV reported.
"The picture was taken in a balcony with protective barriers. These were removed," he was quoted as saying.
The child's father urged the court to forgive the man, saying he had just been playing a game.
However, the judge ruled against him, saying the picture was clear and the child's life was in danger.
Articles shared on social media about the incident got thousands of mostly angry reactions, reports BBC North Africa correspondent Rana Jawad.
Many Algerians insulted the man, and praised the authorities for arresting him and sentencing him, she adds.
Earlier reports incorrectly described the convicted man as the child's father.
A court in Algeria has sentenced a man to two years in prison for dangling a baby out of a window in order to attract "likes" on Facebook.