They (two tribes or peoples) will appear at the time of Jesus son of Mary, after the Dajjaal. Allaah will destroy them all in one night, in response to the supplication of Jesus.
Abu Hurairah reported that the Prophet (صلى الله علیه وسلم) said,
"Everyday, Gog and Magog are trying to dig a way out through the barrier. When they begin to see sunlight through it, the one who is in charge of them says, 'Go back; you can carry on digging tomorrow,' and when they come back, the barrier is stronger than it was before. This will continue until their time comes and Allaah wishes to send them forth. They will dig until they begin to see sunlight, then the one who is in charge of them will say, 'Go back; you can carry on digging tomorrow, inshaa'-Allaah.' In this case he will make an exception by saying inshaa'-Allaah, thus relating the matter to the Will of Allaah. They will return on the following day, and find the hole as they left it. They will carry on digging and come out against the people. They will drink all the water, and the people will entrench themselves in their fortresses. Gog and Magog will fire their arrows into the sky, and they will fall back to earth with something like blood on them. Gog and Magog will say, 'We have defeated the people of earth, and overcome the people of heaven.' Then Allaah will send a kind of worm in the napes of their necks, and they will be killed by it...' 'By Him in Whose hand is the soul of Muhammad, the beasts of the earth will become fat.' " 
Gog and Magog are two groups of Turks, descended from Yaafith (Japheth), the father of the Turks, one of the sons of Noah. At the time of Abraham (alayhi-salam), there was a king called Dhu'l-Qarnayn. He performed Tawaaf around the Ka'bah with Abraham (alayhi-salam) when he first built it; he believed and followed him. Dhu'l-Qarnayn was a good man and a great king; Allaah gave him great power and he ruled the east and west. He held sway over all kings and countries, and travelled far and wide in both east and west. He travelled eastwards until he reached a pass between two mountains, through which people were coming out. They did not understand anything, because they were so isolated; they were Gog and Magog. They were spreading corruption through the earth, and harming the people, so the people sought help from Dhu'l-Qarnayn. They asked him to build a barrier between them and Gog and Magog. He asked them to help him to build it, so together they built a barrier by mixing iron, copper and tar.
Thus Dhu'l-Qarnayn restrained Gog and Magog behind the barrier. They tried to penetrate the barrier, or to climb over it, but to no avail. They could not succeed because the barrier is so huge and smooth. They began to dig, and they have been digging for centuries; they will continue to do so until the time when Allaah decrees that they come out. At that time the barrier will collapse, and Gog and Magog will rush out in all directions, spreading corruption, uprooting plants, killing people. When Jesus (alayhi-salam) prays against them, Allaah will send a kind of worm in the napes of their necks, and they will be killed by it.
 Tirmidhee, Abwaab al-Tafsir: Soorat al-Kahf (Hadeeth 5160), 8/597-99. Ibn Maajah, Kitaab al-Fitan, (Hadeeth 4080), 2/1364. Ahmad, Musnad, 2/510, 511.
Checker's Note: Saheeh, Silsilatul Ahadeeth as-Saheehah: 1735.