Natalie Towers, 24, of Adams Street, Shildon, County Durham, had earlier admitted a charge of administering poison with intent to procure a miscarriage while 32-34 weeks pregnant.
Newcastle Crown Court was told she bought the substance over the internet.
Judge Mr Justice Jay gave her credit for pleading guilty but said she must serve a custodial sentence.
"This offence does involve extinguishing a life about to begin," he said.
Towers was living with her boyfriend in November 2014 when she bought and took a drug which caused strong contractions, the court heard.
After she felt unwell, she rang 999 to say she was having a miscarriage.
Paramedics arrived to find Towers in the bathroom complaining of stomach pain when she said "It's dead, I know it's dead", the court heard.
Strenuous efforts were made to resuscitate the baby, who had been named Luke, the judge was told. The cause of death was oxygen starvation.
Towers initially claimed she was unaware of her pregnancy and had not felt any movements, then confessed she took tablets although "she didn't think she was that far along", Sarah Mallett, prosecuting, said.
After she was arrested, she told police she had searched for the drug on the internet and ordered it without researching it.
Mr Justice Jay said: "The law in this country is quite clear, you must have been fully aware no doubt, in line with your internet searches. It was open to you to seek termination at any stage before 24 weeks gestation."
Dan Cordey, defending, said: "She is remorseful, she greatly regrets her actions... that remorse and regret is something that will live with her for the rest of her life.
"In her own words, she said 'When I look back I think it's awful. I hate myself, I hate it and I know it's my fault'."

Mr Roache, who is secretary of the union's Yorkshire region, won 56.7% of the vote, while the only other candidate, Paul McCarthy, from the North West region, had 43.3%.
The union is the third largest in the UK with more than 600,000 members.
Current general secretary Paul Kenny announced in the summer he was standing down after almost a decade in the job.
Mr Roache has 35 years experience at the GMB and led the Leeds City Council 13-week refuse and street cleaning strike in 2009 - the longest in the union's history.
He said he was "proud and humbled" to have been elected.
"I will repay GMB members' faith in me by leading a 21st Century union that fights for our members, their families and communities, every hour of every day."
Mr Roache also paid tribute to Mr Kenny for his work "that has made GMB the envy of the union movement".
Details of the handover date have yet to be agreed.
The GMB is one of the three largest affiliates to the Labour Party and is a significant financial contributor to the party locally and nationally.
A woman who used poison to terminate her pregnancy has been jailed for two and a half years.
[NEXT_CONCEPT]
Regional official Tim Roache has been elected to become the new general secretary of the GMB union.