The DPP attracted record support, wining 21% of the votes - up from 12.3% in 2011.
Meanwhile, Helle Thorning-Schmidt resigned as prime minister and leader of the Social Democrats, paving the way for Liberal leader Lars Lokke Rasmussen to start talks on forming a government.
Despite overtaking Mr Rasmussen's Liberals - until now the biggest opposition party - the eurosceptic DPP may not be part of the new coalition.
Its leader Kristian Thulesen Dahl said the party might be more efficient in opposition.
Mr Dahl, who took the reins of the DPP in 2012, has led the party to increasing popularity amid public concern over the cost of immigration to Denmark's welfare state.
The party has toned down some of its more inflammatory rhetoric on asylum seekers and Islam, and veered to the left on economic issues.
As well as tougher restrictions on asylum seekers, it campaigned in the election for higher pensions for low-income earners and more money for healthcare and the elderly.
Correspondents say the shock result also brings UK PM David Cameron a powerful new ally in his bid for EU renegotiations.
The DPP wants Denmark to leave the Schengen area - boosting border controls is one of its top issues - and to make it harder for EU migrants to claim benefits in other member states.
Formed in 1996, the DPP is a relative newcomer in Danish politics.
In May 2002, the country's Liberal-Conservative government - largely dependent on the DPP's support - introduced what it described as Europe's strictest immigration laws, reducing the grounds for being granted asylum and cutting benefits.
Like many other nationalist parties across Europe, the DPP was Denmark's biggest winner at the European Parliament elections in 2014 - taking nearly 27% of the vote.
The party now sits with the European Conservatives and Reformists group in the European Parliament, alongside Mr Cameron's Conservative Party and the euro-sceptic Alternative for Germany party.
The anti-immigration Danish People's Party (DPP) has become Denmark's second largest political party after a general election that saw the ruling coalition lose power.