Raya, who has replaced England international Aaron Ramsdale as first-choice at Arsenal, has made 41 appearances in all competitions since his season-long loan move from Brentford.
The Spain keeper moved to the Bees in 2019 after a spell at Championship side Blackburn Rovers.
Arsenal did not disclose the financial details of the deal, but British media reported that they have paid about 27 million pounds ($34.45 million) for Raya.
"David showed us last season what an important player he is for us, so we are delighted he is now officially our player," Arsenal manager Mikel Arteta said in a statement.
"He is a big presence in our dressing room and we are really pleased to keep working with him.
"We know he will take the strong foundations he put in place last season and build on them in the years to come, and that he will enjoy more success with us.
"We have a very talented group of goalkeepers and I love to see connections like the one I see in our goalkeeping unit."