Modi has been criticised for focusing on the elections instead of making the pandemic his top priority.
Some expert blame the federal election commission for allowing rallies and voting in which large crowds flouted rules on social distancing and mask-wearing.
Banerjee is now India's only woman chief minister.
Despite the defeat, Modi's Bharatiya Janata Party (BJP) made substantial gains, making it the main opposition party as its tally in the state legislature went to nearly 80 seats from just three seats won in 2016.
Banerjee, a sharp critic of Modi, largely conducted a one-woman campaign to retain power by leading scores of public rallies.
"It is a stupendous performance by Mamata Banerjee because Modi was determined to win Bengal, but it's clear that his entire political machinery and strategy was unable to defeat her," said Diptendu Bhaskar, a political analyst in Kolkata, West Bengal's capital.
In Assam state, the BJP managed to retain political power. In Tamil Nadu, the DMK - the main regional opposition party - secured victory
In Kerala state, the ruling lefist political party was set to form government while the BJP led-alliance won no seats. In the union territory of Puducherry, the All India NR Congress-led alliance was leading in 14 of the 30 seats assembly.
Most of the votes were cast in March, but polling in some constituencies continued through April, just as India started to detect thousands of new coronavirus infections everyday.