The poll was the first electoral test for Modi's Bharatiya Janata Party after it passed a controversial nationality law which opponents say is anti-Muslim.
Aam Aadmi Party supporters cavorted to bhangra music and set off fireworks as the vote count showed they had crossed the 36 seats needed to secure a majority in the 70-seat regional assembly.
Hindu-nationalist Modi, whose party swept to power in national elections last year, congratulated AAP leader Arvind Kejriwal, the incumbent Delhi chief minister.
"Wishing them the very best in fulfilling the aspirations of the people of Delhi," Modi tweeted.
Congratulations to AAP and Shri @ArvindKejriwal Ji for the victory in the Delhi Assembly Elections. Wishing them the very best in fulfilling the aspirations of the people of Delhi.
— Narendra Modi (@narendramodi) February 11, 2020
The BJP had launched an aggressive campaign to win the city of nearly 20 million people from the AAP, using the election to rally support for the law easing citizenship rules for religious minorities from Bangladesh, Pakistan and Afghanistan, but excluding Muslims.
At least 25 people have been killed in protests over the legislation so far.
But the AAP, which swept to power in 2015 after it was launched three years earlier by former tax officer Kejriwal, retained control in an impressive showing.
The defeat in Delhi is the latest in a string of setbacks for the BJP at regional elections over the past two years.
Kejriwal, 51, fought the election on local issues such as subsidised water and electricity, as well as the safety of women.
"This win has given birth to a new type of politics -- the politics of work," he told cheering supporters at party headquarters.
"This is the type of politics that will take the country forward in the 21st century."
Yogendra Yadav, an academic who was a member of the AAP executive until 2015 and now has his own party, said the result was a clear rejection of Modi and his party's angry campaign.
"The BJP indulged in one of the most vitriolic, communal hate mongering campaigns as a desperate electoral gamble," he told AFP.
"If this succeeded, it would have become a template for everyone else to follow.
Congress, led by the storied Gandhi-Nehru dynasty and the main opposition at the national level, was set to draw a blank in another low for a party that ruled Delhi for 15 years before AAP took over.
Final results from the Election Commission of India were not expected until late Tuesday.
COMMENTS
Comments are moderated and generally will be posted if they are on-topic and not abusive.
For more information, please see our Comments FAQ