The former Bradford Bulls forward will join ahead of 2020 as Leeds start their rebuilding job at Emerald Headingley.
Mellor, 24, has earned great reviews this season, scoring seven tries in 14 appearances at Huddersfield who had hoped to extend his stay.
However, the Halifax-born forward, who joined from Bradford Bulls in 2017, will now continue his promising career in Leeds colours.
Mellor, who scored a hat-trick in the recent win over Castleford Tigers, said: "I am really grateful for the opportunity to join Leeds Rhinos and can’t wait to get started next season.
"I have had two fantastic years at Huddersfield and am grateful for everything they have given me.
"Leeds is a great club and, whilst they are having a tough season so far hopefully I can play my part in helping the team get back to where they belong.
"It is a huge club and I am excited about being part of the process to rebuild the club’s fortunes on the field.
"I live locally and, whilst I had a couple of offers to move elsewhere, Leeds was always my first choice.”
Rhinos director of rugby Kevin Sinfield said: “We are delighted to have secured Alex on a long-term deal with the club.
"He is an exciting young English forward who has developed his game since returning to Super League with the Giants.
"Despite only being 24, he has over 100 senior appearances already and I am sure he will continue to progress within our system."