Voluntary euthanasia is set to become legal in Victoria after historic laws passed the upper house despite ferocious opposition from conservative MPs.

The bill passed the upper house with 22 votes to 18, after a marathon 28-hour sitting.

Although the bill has already passed the lower house with a strong majority it must go back in its amended form for a final vote.

Both government and opposition MPs were granted a conscience vote on the bill, freeing them from being bound by party lines. The bill was debated by both houses of parliament for about 100 hours.