The federal government has passed legislation that bans whale and dolphin captivity in Canada.

The bill will phase out the practice of keeping captive whales, dolphins and porpoises, but grandfathers in those that are already being held at two facilities in the country.

Marineland in Niagara Falls, Ont., and the Vancouver Aquarium in B.C. are the only two places that currently keep captive cetaceans.

The bill bans the capture of wild cetaceans, captive breeding and the import and export of those animals, with limited exceptions.

It allows for the rehabilitation and rescues of cetaceans.

The bill was first introduced in the Senate in 2015 and eventually made its way into the House of Commons, where it had its third and final reading today.