The Dutch World Cup runner-up had been the subject of constant transfer speculation after struggling to nail down a starting place in his first season at the San Siro last term.
He joins former Real Madrid teammate Raul at Schalke, last season's Bundesliga runners-up.
"Negotiations were tougher than expected. I am happy to have Klaas-Jan. He will help us," Schalke boss Magath told Bild newspaper early on Tuesday.
Schalke, playing in the Champions League this season, have lost both their opening Bundesliga matches.
The 27-year-old, who played for four years at Ajax Amsterdam before moving to Real in 2009 where he also failed to establish himself, said on his website late on Monday he hoped the deal would go through before the end of the day.
"Klaas-Jan wants to continue his career at Schalke. Schalke and Milan have agreed on a transfer fee of about 13 million euros," he said on www.klaasjanhuntelaar.com.
"It is true I never wanted to leave Milan but that changed when Zlatan Ibrahimovic came from Barcelona," he said.
Raul signs two-year contract with Schalke
Huntelaar double helps Milan beat Udinese
Debutant Matip helps Schalke hold Bayern
Schalke denied top spot by Pitroipa's late goal
Bayern beat Wolfsburg 2-1 in Bundesliga opener