The 21-year-old centre-back joined the Championship club on loan in March and Cardiff boss Russell Slade has now made the move permanent.
The Charlton Athletic product has been capped for Nigeria at Under-21 level.
Ajayi was an unused substitute in Cardiff's final league match of last season away at Nottingham Forest.
Born in Crayford, south London, Ajayi joined Arsenal from Charlton Athletic's Academy in 2013 and was a regular for the Gunners' Under-21s last season.
Ajayi was an unused substitute for Arsene Wenger's side in Premier League games against Newcastle United, Stoke City and Hull City.
His Arsenal contract expired at the end of June and Ajayi was then free to join Cardiff.