Suspect Tim K. told others in the chat room that he was "sick of this life" and planned to attack his school in Winnenden, Baden Wuerttemburg state Interior Minister Heribert Rech said.
Rech said the suspect wrote, "You will hear from me tomorrow, remember the name of a place called Winnenden."
In the first indication of a motive in the shooting, Rech said the teenager told others in the German-language chat room that: "Everyone laughs at me, nobody recognizes my potential."
"I'm serious, I have a weapon here," Rech said the youth wrote. "Tomorrow I will go to my school."
Rech said that the chat had occurred the night before the attack, but a police official, Erwin Hetger, later said it was in the early morning Wednesday, about six hours before the 9:30 a.m. shooting.
A Bavarian man told police about the chat after the school shooting in Winnenden had taken place, Rech said. He told authorities his 17-year-old son only told him about it after seeing the news reports and had not taken the threat seriously.
Despite the high death toll, the shooting could have been worse if the principal of the high school had not been able to warn teachers with a prearranged code over the public address system when the suspect burst into the school.
According to media reports, after the suspect entered the school in Winnenden on Wednesday morning and opened fire, the principal put the emergency plan in effect, quickly broadcasting a coded message to teachers: "Frau Koma is coming," students said.
"Then our teacher closed the door and said we should close the windows and sit on the floor," a student, identified only as Kim S., told ZDF television.
In German the word "amoklauf" is used to describe school shootings, and "koma" is the reverse of the word "amok." Hetger said the coded alert was worked out by German educators after a deadly school shooting in Erfurt in 2002 as a way to warn teachers.
Local media have identified the gunman as Tim Kretschmer and the name on his parent's home was Kretschmer.
After he escaped from the school Wednesday, he hijacked a car and was eventually caught in a police shootout. The rampage ended with 15 victims slain and the assailant taking his own life, authorities said.
The high school was closed Thursday, still cordoned off by red and white police tape as investigators pored through the building. Scores of candles lit by mourners adorned the grounds amid bunches of flowers and notes with messages and questions like "Why?"
A man carried a sign saying, "God: Where were you?"
The government ordered all federal buildings to fly their flags at half staff, and schools across the country held moments of silence for the victims. 's national soccer league, the Bundesliga, said players would wear black armbands in upcoming games.
Authorities still have not given any indication of the gunman's motive. His victims were primarily female: eight of nine students killed were girls, and all three teachers were women. Three men were killed later by the suspect as he fled.
Injured student Patrick S., 15, was quoted by Bild newspaper as saying Kretschmer burst into his German class at about 9:30 a.m.
"We flipped over the desks to duck behind for cover. ... Suddenly I saw that I was hit - in the back, in the arm and in the cheek," he was quoted as saying. "Suddenly he was gone and we barricaded the door. And then I saw my classmate Chantal. She sat at the door. Dead."
Local police spokesman Nik Brenner said that authorities had found 60 shell casings in the school.
Friends and acquaintances described Kretschmer as a loner who liked guns and violent video games.
A 17-year-old who would give only his first name, Aki, said he had been studying this year with the shooter at a private business school, and described him as a quiet, reserved person.
Aki said the two played poker together, both in person and online, as well as a multiplayer video game called "Counter-Strike" that involves killing people to complete missions. He was good at it, Aki said.
Brenner said that authorities had searched Kretschmer's computer and found violent video games on it, but was not more specific.
The dark-haired teen, shown wearing glasses in pictures on German television, apparently took the weapon from his father's collection of 15 firearms along with a "multitude of ammunition," police said. His father, a businessman, was a member of the local gun club and kept the weapons locked away except for the pistol, which was kept in the bedroom.
A 19-year-old, whose name was not given, was quoted by Bild as saying his parents were friends with Kretschmer's and that they had asked him to play with him "because he had no friends."
He said Kretschmer had at least 30 air guns that shot plastic pellets in his room, and that his father had built a shooting range in his basement for him to practice with them, Bild reported.
"When we went outside he shot at us with the air pistols and wouldn't stop," the boy was quoted as saying. "It really hurt - so nobody wanted to play the game any more."