Prime Minister David Cameron has secured the backing of all three main parties for the highly unusual move.
He said urgent action was needed to protect the public from "criminals and terrorists" after the European Court of Justice struck down existing powers.
But civil liberties campaigners have warned it will invade people's privacy.
Mr Cameron defended the move in a joint news conference with Deputy Prime Minister Nick Clegg, saying it was about maintaining existing capabilities - not introducing new snooping laws.
But it will make legally clear the requirements include companies based abroad, whose phone and internet services are used in the UK. A former senior diplomat will also be appointed to work with other nations to speed up the "lawful and justified" transfer of data across borders.
Mr Cameron also said he had reached an agreement with Labour leader Ed Miliband for a wider review of the surveillance powers needed by the security services, to report after the next election.
Key questions answered
What is the emergency legislation?
The legislation is primarily aimed at the companies that provide us with telephone and internet connections. It outlines their legal obligation to retain "communications data" on their customers. This metadata includes things like logs of when calls were made, what numbers were dialled, and other information that can be used, the government says, in investigations. It does not include the content of the communications.
Will it mean the government can listen in to my calls?
Not exactly. The vast majority of people will only have data collected on things such as the time a call is made and the number that was called - not the actual contents of that communication. But the emergency law does go further - the law reinforces the ability of authorities to carry out what is known as a "legal intercept". This is when a target is identified for additional monitoring - including listening in to phone calls and other communications.
Read the full guide
Mr Cameron said: "We face real and credible threats to our security from serious and organised crime, from the activity of paedophiles, from the collapse of Syria, the growth of Isis in Iraq and al Shabab in East Africa.
"I am simply not prepared to be a prime minister who has to address the people after a terrorist incident and explain that I could have done more to prevent it."
He added: "I want to be very clear that we are not introducing new powers or capabilities - that is not for this Parliament.
"This is about restoring two vital measures ensuring that our law enforcement and intelligence agencies maintain the right tools to keep us all safe."
In return for agreeing to back the legislation, Labour and the Lib Dems highlighted new moves to "increase transparency and oversight", including:The creation of a new Privacy and Civil Liberties Oversight Board to scrutinise the impact of the law on privacy and civil liberties Annual government transparency reports on how these powers are used The appointment of a senior former diplomat to lead discussions with the US government and internet firms to establish a new international agreement for sharing data between legal jurisdictions A restriction on the number of public bodies, including Royal Mail, able to ask for communications data under the controversial Regulation of Investigatory Powers Act (RIPA) Termination clause ensuring these powers expire at the end of 2016 A wider review of the powers needed by government during the next parliament
Mr Cameron stressed that the data being retained does not include the content of messages and phone calls - just when and who the companies' customers called, texted and emailed.
But the emergency Data Retention and Investigation Powers Bill would also "clarify" the law on bugging of suspects' phones by the police and security services, when the home secretary issues a warrant, after concerns service providers were turning down requests.
"Some companies are already saying they can no longer work with us unless UK law is clarified immediately," said Mr Cameron.
"Sometimes in the dangerous world in which we live we need our security services to listen to someone's phone and read their emails to identify and disrupt a terrorist plot."Analysis
By Nick Robinson, BBC Political Editor
Critics will no doubt argue that the time for a debate about what powers will replace this law is now. To pass any new law in just a week is rare. So too is it to have the backing of all three main parties even before it is published. Read more from Nick
The government says it was forced to act after the European Court struck down an EU directive in April requiring phone and internet companies to retain communications data on the grounds that it infringed human rights.
Emergency legislation was needed, the government argues, because service providers were being threatened with legal action by campaigners if they did not start destroying data, some of which could prove vital to criminal investigations and court cases.
But Conservative MP and former shadow home secretary David Davis, a longstanding campaigner on civil liberties, accused the government of staging a "theatrical emergency," adding that ministers had "plenty of time" to come up with a response to April's court ruling rather than rushing it through Parliament without proper scrutiny.
"This is complicated law, it needs to be got right," he told BBC Radio 4's The World at One.
By Gordon Corera, BBC security correspondent
There is no doubt that gathering communications data can be a powerful tool. Officials say it has played a role in almost all serious criminal cases and counter-terrorist investigations in recent years.
But the political context around its use has changed - partly but not entirely due to the Edward Snowden revelations. It has led commercial communications companies to become nervous about being seen to help government too readily and to them demanding more clarity over the law.
Overall, the new environment has led to more questions being raised about whether there is sufficient transparency, accountability and oversight.
Shami Chakrabarti, director of campaign group Liberty, said: "We are told this is a paedophile and jihadi 'emergency', but the court judgment they seek to ignore was handed down over three months ago and this isn't snooping on suspects but on everyone."
David Cameron believes existing surveillance powers do not go far enough and he repeated his promise to push ahead with plans for a giant database of all websites visited by UK citizens, dubbed a "snooper's charter" by critics, if he wins the next election.
Nick Clegg blocked attempts by this government to pass the "snooper's charter" - but he said he had been convinced of the need for the more limited powers contained in the emergency Data Retention and Investigation Powers Bill.
The legislation contains what Mr Clegg described as a "poisoned pill" which will mean the powers cease at the end of 2016, in an effort to ensure the next parliament takes a more considered look at the issue.Shami Chakrabarti says the emergency legislation is about "snooping on everyone"
The Lib Dem leader said successive governments had "neglected civil liberties as they claim to pursue greater security", but added: "I wouldn't be standing here today if I didn't believe there is an urgent challenge facing us.
"No government embarks on emergency legislation lightly but I have been persuaded of the need to act and act fast."
The bill will be pushed through Parliament in seven days - a process that normally takes several months.
MPs will be given a chance to debate it in an extended Commons sitting on Tuesday, but Labour's Tom Watson said they would not get time to properly consider the plans and he branded it a "stitch-up".
But Mr Watson was one of the few MPs to voice doubts about the legislation in the Commons earlier, where Home Secretary Theresa May accused the Labour MP of finding a "conspiracy at all costs".
Labour leader Ed Miliband and shadow home secretary Yvette Cooper confirmed that Labour would support the emergency legislation, telling the party's MPs in a letter: "Serious criminal investigations and counter terrorism intelligence operations must not be jeopardised.'Lateness of legislation'
"That is why we are supporting this emergency legislation which we accept is designed solely to protect existing capabilities."
But Ms Cooper said: "There will be serious concern in Parliament and across the country at the lateness of this legislative proposal and the short time to consider something so important."
The Open Rights Group, which has been pushing service providers to start destroying data following the European Court ruling, criticised the government for using the threat of terrorism to push through an "emergency law" that it says has no legal basis.
Executive Director Jim Killock said: "Not only will the proposed legislation infringe our right to privacy, it will also set a dangerous precedent where the government simply re-legislates every time it disagrees with a decision by the CJEU.
"The ruling still stands and these new plans may actually increase the amount of our personal data that is retained by ISPs, further infringing on our right to privacy.
"Blanket surveillance needs to end. That is what the court has said."
Scottish Justice Secretary Kenny MacAskill has accused the UK government of a "lack of prior consultation", adding that the legislation could affect Scots law and matters devolved to the Scottish government.