The incident happened shortly after 1am
Armed gardai deployed a stinger device - used to immobilise vehicles - on a man driving the wrong way on the M7 near Naas.
He was also prosecuted for driving with excess alcohol on the same occasion.
Sgt Jim Kelly said the defendant was driving northbound towards Dublin at 1.05am - on the southbound carriageway.
He added that the defendant avoided the stinger but this action slowed him so the gardaí could execute a “controlled stop.”
He added that the car had driven a distance of five or six miles and the driving would have put the gardai and members of the public at risk.
The court was told that the defendant struggled violently when the vehicle was stopped.
Members of the Garda armed support unit, which normally assists in serious criminal investigations, were involved in the operation - though there was no suggestion of serious crime in this case.
Barrister Sarah Connolly said the defendant is from Moldova and has been in Ireland for three years.
She added he came here to earn a better living and has family member in Moldova.
“It’s dreadful set of circumstances, “ added Ms Connolly.
Ms Connolly noted the defendant has no previous convictions and this was described as a one off incident.
Judge Desmond Zaidan said that no accident had taken place and the gardaí may well have saved the defendant’s life.
He imposed consecutive five month custody terms on each dangerous driving case along with a concurrent four year driving disqualification on each. He was also disqualified from driving for four years for driving with excess alcohol and also for having no insurance. All disqualifications will run concurrently.