The 35-year-old centre-back had been out of contract after helping Villarreal back to the Spanish top flight last season.
Copenhagen sporting director Carsten V Jensen believes the club is fortunate to have acquired a player with the experience of the former Aston Villa and Juventus man.
"It is an unusual amount of experience that we have brought to Copenhagen in Olof Mellberg," Jensen told the club's official website.
"And through our conversations with him, we are certain that his hunger and winning instinct is still intact and a part of his personal drive."
FC Copenhagen have already secured their spot in the group stages of the UEFA Champions League for the forthcoming season as champions of Denmark.