"There was sustained and gratuitous racism. These were unprovoked comments and persistent abuse. The recipients were disgusted."
Jailing the student at Swansea Magistrates' Court, District Judge John Charles said: "Not just the footballer's family, not just the footballing world, but the whole world were literally praying for Muamba's life. Your comments aggravated this situation.
"I have no choice but to impose an immediate custodial sentence to reflect the public outrage at what you have done."
Stacey made his comments about the 23-year-old Bolton Wanderers midfielder while celebrating the Welsh rugby team's Six Nations grand slam victory earlier this month.
The judge added: "You committed this offence while you were drunk and it is clear you immediately regretted it. But you must learn how to handle your alcohol better."
Stacey, from Pontypridd, South Wales, told police following his arrest at his student home in Swansea: "I was at the bar when I heard what had happened to Muamba. I don't know why I posted [the comments]. I'm not racist and some of my friends are from different cultural backgrounds."
He later sent a text message to a friend saying: "I said something about Muamba that I shouldn't have and tweeted back to some people who abused me. Getting police on me now which isn't good at all."
Another read: "Been bawling my eyes out on the phone to my mother for the last hour, really can't be dealing with this."
Gareth Jones, defending, said Stacey "does not bear [Muamba] any grudge and is glad he is making a good recovery". He continued: "My client simply lost his head and posted these disgusting comments to the bitter shame of himself and his parents. For a moment of madness, his career has now gone."
Stacey's father Neale, 49, and mother Hayley, 46, were visibly shocked when the details of his comments were read aloud yesterday.
Jim Brisbane, chief crown prosecutor for CPS Cymru-Wales, said: "Racist language is inappropriate in any setting and through any media. We hope this case will serve as a warning to anyone who may think that comments made online are somehow beyond the law."
Yesterday Muamba was said to be continuing to make good progress at the London Chest Hospital, where he was visited by his Bolton teammates ahead of their rescheduled FA Cup match against Tottenham Hotspur.
The game was abandoned on March 17 following Muamba's collapse.