The seat, held by Hukum Singh, leader of the BJP legislature party in the state and now an MP, was won by SP's Nahid Hasan by a margin of 1,099 votes.
According to the Election Commission, Hasan polled 83,984 votes and the BJP candidate Anil Kumar, Hukum Singh's nephew, polled 82,885 votes. Congress candidate Arshad Hasan was at the distant third position with 16,906 votes.
This is the second setback for the BJP in the past four months after its sweep in the Lok Sabha polls when it won 71 of the state's 80 parliamentary seats.
The SP wrested eight seats from it in a bypoll and Sunday's results are only going to add to their woes. Kairana was won by the BJP in the 2012 assembly polls when Hukum Singh defeated Bahujan Samaj Party's (BSP) Anwar Hasan by 19,000 votes.
BJP state spokesman, Vijay Bahadur Pathak, while conceding that the loss was a setback even though it was by a slender margin, said the party will take stock of the defeat and initiate course correction as it braces up for its Mission 2017, when the state will go for assembly polls.
Samajwadi Party spokesman Rajendra Chowdhary said the results had proved beyond doubt that the "communal politics" of the BJP will not succeed in UP.