The Spanish giants will pay the Austrian club €500,000 as part of the loan move, with an option to make Demir's stay permanent for €10 million.
Demir, 18, has scored six goals in 31 games since being promoted to Rapid's first team in the summer of 2019 and had been a target for Manchester United and Bayern Munich, sources have told ESPN.
The Austria international made his senior team debut in a 2022 World Cup qualifier victory over the Faroe Islands in March.
Demir, who can play across the attack, is expected to start the season with Barca's B team.
Barca begin preseason training on Monday without the players that are on international duty and with the uncertainty of who will remain at the club.
His contract expired last month and La Liga have warned Barca it must reduce its wage bill to register Messi next season and remain within the league-imposed salary cap. Barca coach Ronald Koeman is hopeful Messi will remain.
"It is very important for the club, but also for La Liga that the best player in the world stays here and we all must make that effort so that he continues with us," Koeman said on Friday while taking part in a golf tournament, the Koeman Cup, in Barcelona.
"When everything is not going well, you have to be worried, but I am confident that the [club] president [Joan Laporta] will find a solution to this issue.
"Each person has an assignment, but Laporta has told me I do not have to stress over this, that the issue is being worked on. We trust that he will be with us for a few more years.
"Leo is the future of the club because he brings results and because he has always given his best."
Koeman said the departures of Carles Alena, Junior Firpo, Francisco Trincao and Matheus Fernandes this summer, as well as the sales of Jean-Clair Todibo, Sergio Akieme and Konrad De La Fuente, were done to help the club remain within the salary cap.
The Barca boss stressed that the players that remain must take a wage cut to "make an effort for the good of Barcelona."
"Everyone has to understand the place we are in our lives right now," Koeman added. "If they [players] truly are 'Barcelona people' then they have to make this great effort to help the club."
Koeman praised Antoine Griezmann amid reports that he could be placed on the transfer list this summer to make room to register Messi's contract.
Griezmann, who scored 20 goals and set up 13 more in 51 appearances in all competitions last season, has a contract with Barca that runs until 2024.
Barca begin the 2021-22 season against Real Sociedad at the Camp Nou on August 14/15.