Google will now pay for news content that appears on its "Showcase" product and Facebook is expected to pay providers who appear on its "News" product, which is to be rolled out in Australia later this year.
Regulators had accused the companies, who dominate online advertising, of draining cash away from traditional news organisations while using their content for free.
Big tech firms had fiercely opposed the legislation from the outset, fearing it would threaten their business models.
In particular, the companies objected to rules that made negotiations with media companies mandatory and gave an independent Australian arbiter the right to impose a monetary settlement.
That prospect was dramatically reduced by last-minute government amendments.
"Importantly, the code encourages parties to undertake commercial negotiations outside the code and the government is pleased to see progress by both Google and more recently Facebook in reaching commercial arrangements with Australian news media businesses," Treasurer Josh Frydenberg said in a statement.
Google was also keen to avoid creating a precedent that platforms should pay anyone for links, something that could make their flagship search engine unworkable.
Facebook - which is much less reliant on news content - had initially said being forced to pay for news was simply not worth it and shut down access to news content for its Australian users.
'Public interest journalism' The government said the law, called the News Media and Digital Platforms Mandatory Bargaining Code, would ensure that news businesses "are fairly remunerated for the content they generate, helping to sustain public interest journalism in Australia".
Facebook and Google now have an additional two months to reach further agreements that would stave off binding arbitration.
Google has already brokered deals worth millions of dollars with local media companies, including the two largest: Rupert Murdoch's News Corp and Nine Entertainment.
Facebook on Tuesday lifted a site-wide ban on Australian news, introduced in protest at the law, and announced its first proposed deal with an Australian media company, Seven West.
Both Facebook and Google have each said they will invest around $1 billion (roughly Rs. 7,230 crores) each in news around the world over the next three years.
Critics of the law say it punishes innovative companies and amounts to a money-grab by struggling - but politically connected - traditional media.
Tech insiders see the legislation as driven, in particular, by Rupert Murdoch's News Corp, which dominates the local media landscape and has close ties with Australia's conservative government.
Nick Clegg, head of global affairs, on Thursday said the original draft of the law would have forced Facebook to pay "potentially unlimited amounts of money to multinational media conglomerates under an arbitration system that deliberately misdescribes the relationship between publishers and Facebook".
Thousands of journalism jobs and scores of news outlets have been lost in Australia alone over the past decade as the sector watched advertising revenue flow to the digital players.
For every $100 (roughly Rs. 7,230) spent by Australian advertisers today, $49 (roughly Rs. 3,550) goes to Google and $24 (roughly Rs. 1,730) to Facebook, according to the country's competition watchdog.