"The next day John saw Jesus coming toward him, and said, 'Behold! The Lamb of God who takes away the sin of the world! This is He of whom I said, "After me comes a Man who is preferred before me, for He was before me." I did not know Him; but that He should be revealed to Israel, therefore I came baptizing with water.' And John bore witness, saying, 'I saw the Spirit descending from heaven like a dove, and He remained on Him. I did not know Him, but He who sent me to baptize with water said to me, "Upon whom you see the Spirit descending, and remaining on Him, this is He who baptizes with the Holy Spirit." And I have seen and testified that this is the Son of God'" (John 1:29-34).
It appears that Jesus had just returned from the temptations in the wilderness. This is His first appearance in John's account of the gospel. Jesus is called a "Lamb" because He was to be a perfect sacrifice. Many passages of Scripture speak of Jesus in this way (e.g., Isa. 53:7; I Cor. 5:7; I Pet. 1:19; Rev. 5:6-12). He is the lamb "of God" in that He was given out of love by the Father as a sacrifice for the world (cf. John 3:16). Ultimately, Jesus is the sacrificial lamb given by God for the purpose of taking "away the sin of the world." Jesus bore our sins as if He were guilty of them even though He was completely innocent (cf. Isa. 53:6,11; Matt. 8:17; II Cor. 5:21).
John admitted that initially he "did not know Him" (John 1:31). We know from other Scriptures that John knew Jesus to some extent (cf. Matt. 3:14), but he did not have certain enough knowledge (yet) to testify that Jesus was the Christ and reveal Him as such. One of the purposes of John's baptism was to reveal the Messiah to Israel. John baptized not only that he himself might know Christ by the spiritual sign (mentioned in 1:32,33), but also that he might testify of the Christ so all Israel would know.
The apostle John then records a flashback: John the baptizer tells of what he personally witnessed at Jesus' baptism (i.e., the Spirit descended like a dove and remained upon Him). God had foretold John the baptizer what this sign meant. Jesus was (and is) the Messiah!
John the baptizer is the first witness that John the apostle makes record of. There is now no doubt in John the baptizer's mind as to Jesus' identity. John was an eyewitness, and willing to testify that Jesus is "the Son of God," because he has seen the promised sign and heard the Father speak from heaven.