 Ansari started his political career with the Communist Party of India.He contested Uttar Pradesh Legislative Assembly election in 1985 for the first time and defeated his close contestant Abhay Narayan Rai from Indian National Congress with a margin of 3064 votes.From 1985 to 2002, he served five terms as Member of the Legislative Assembly from Mohammadabad (Assembly constituency).