The winger put pen to paper on the deal -- which includes a €1 billion ($1.05bn) release clause -- at Barça's training ground on Monday at an event also attended by president Joan Laporta and sporting director Deco.
Until he turns 18, Yamal cannot sign a contract for longer than three years, which is the reason he has not signed longer terms.
It has been a record-breaking year for the forward, who made his first team debut in April while he was still 15, becoming the youngest player to represent Barça in LaLiga. He has since gone on to become the youngest player to ever play and score for Spain, netting on his debut against Georgia earlier this month.
Meanwhile, at club level, he has established himself in Xavi Hernandez's squad, making nine appearances in all competitions so far this season, including four starts. He set up the winner, an own goal by Sergio Ramos, in Friday's 1-0 victory over Sevilla in LaLiga as Barça maintained their unbeaten start to the campaign.
Further records could fall in the coming weeks, with Yamal still able to become the youngest-ever goal scorer in LaLiga and the Champions League. That record is held by Ansu Fati in the Champions League, whose goal against Inter Milan for Barça in 2019 came when he was 17 years and 40 days old.
In LaLiga, though, he is running out of time. He has just one game left -- away at Granada on Sunday -- to beat the mark set by Fabrice Olinga, who was 16 years and 98 days old when he scored for Malaga a decade ago.
Yamal first joined Barça in 2013 from local Catalan club CF Torreta and has since progressed through the academy, racing through the age groups until reaching the first team this year.