The Samajwadi Party (SP) and the Bahujan Samaj Party (BSP), two political rivals in Uttar Pradesh, will form an alliance in a bid to defeat Prime Minister Narendra Modi's Bharatiya Janata Party (BJP) in national election scheduled for May, leaders of the parties said.

The SP and the BSP, both of whom command large support bases among state's working class and are led by former chief ministers, will contest the election as a team, they said.

Uttar Pradesh is India's most populous state and accounts for about a sixth of all members of the parliament. Barring a couple of exceptions in the 1990s, the party winning the most number of seats there has historically helped form the federal government.

It is not clear how the seats will be allotted and what role the main opposition Congress party will have in the state, but SP's chief Akhilesh Yadav hinted that it will not have a significant role to play.

Congress, which ruled India for nearly four decades since its independence from Britain in 1947, is working to build a so-called "grand alliance" with other parties in preparation for the vote.

"We can give Congress two seats they have always held," Yadav told news channel NDTV, referring to constituencies from where Congress President Rahul Gandhi and his mother Sonia Gandhi have contested in the past.

An SP spokesperson declined to elaborate, and said further details will be revealed in a joint news conference by the SP and BSP on Saturday.

Opposition parties across the country received a fillip last month, when India's ruling party lost power in three states and dealt Prime Minister Narendra Modi his biggest defeat since he took office in 2014.

The BJP, SP and BSP contested against each other during the state elections in March 2017, which the BJP comfortably won, but political analysts say an SP-BSP alliance could affect the ruling party's prospects.

The BJP had a 40 percent vote share in the state polls, the BSP and SP put together accounted for 44 percent. To be sure, voting patterns could be different when the world's largest democracy goes to polls.

Despite recent setbacks, the BJP is confident of winning elections in Uttar Pradesh, its president Amit Shah said in a televised address.

"We will win 74 out of the 80 seats in Uttar Pradesh," he said.

Despite the strategic significance and having been ruled by different parties since independence, the state remains one of India's most backward.