The candidature of Babu, who had a controversial stint as excise minister, was opposed by KPCC Chief V M Sudheeran.
Babu, who had been winning the seat since 1991, got the ticket following Chief Minister Oommen Chandy's intervention.
Overcoming problems created by factionalism in the CPI(M) in Thrippunithura, Swaraj defeated 64-year-old Babu by a margin of 4,467 votes.
Babu had won the 2011 elections by a margin of 15,778 votes against his nearest CPI(M) rival, C M Dinesh Mani.
Also Read
He returned to the cabinet on February 1 after the Kerala High Court stayed the order.
The resignation of Babu, a close confidante of Chandy, had rattled the UDF government.
Working President of Kerala Bar Owners Association Biju Ramesh had alleged that Babu was given Rs 10 crore as bribe for renewal of licences of liquor bars, a charge rubbished by the Congress leader.