The legislation will define social media services as the publisher of the comments, allowing them to be the target of a defamation claim in an Australian court.
If a claim goes to court, a social media platform will also be required to "unmask" a troll by providing an email address, a mobile phone number or relevant personal detail.
Prime Minister Scott Morrison said an important part of free speech in Australia was being held responsible for what a person says.
"In a free society such as Australia where we value our free speech, it is only free when that is balanced with the responsibility for what you say," Mr Morrison said.
"Free speech is not being allowed to cowardly hide in your basement and sledge and slur and harass people anonymously and seek to destroy their lives."
The Prime Minister said the bill will go out for consultation and he expects to receive strong support from the Parliament.
"The online world should not be a wild west where bots and bigots and trolls and others are anonymously going around and can harm people and hurt people, harass them and bully them and sledge them," Mr Morrison said.
"That is not Australia.
"That is not what can happen in the real world, and there is no case for it to be able to be happening in the digital world."
Attorney-General Michaelia Cash said if the legislation passes, online trolls will not be allowed to hide behind anonymous accounts.
"We will also put in place another mechanism for people who are subject to defamatory comments. They will be able to apply to the Federal Court of Australia for an end user discloser order," Ms Cash said.
"In other words, they will be able to go to the Federal Court and say, 'I believe I have been defamed, and I am unable to take this action any further because this person is at this point in time anonymous'.
"The court will, therefore, be able to issued to the social media and order that they provide the complainants with the details to unmask the troll so that the complainant is able to take action against them."