The Christian doctrine of the Trinity was formulated in the first 300 years as believers came to realize the full deity of both Jesus and the living Spirit that sustained them. Clues were throughout the letters of Paul as well as those of John.
In short, the definition of God as One God, but in Three "persons" became necessary to fully bring glory to God in worship. The name of Jesus means "Yah Saves" (that is YHWH saves). Since the man Jesus is the promised Savior, then the prophet's declaration that 'there is no Savior but YHWH" has to be fulfilled in him. When Jesus refers to God as His Father, and to himself as the Son of God, the two "persons" of God are defined in that relationship. See Son of God.
In all four gospel the Holy Spirit ("the Spirit, the Holy One") is treated as personal. In the Acts, "the Holy Spirit" is used in parallel with "God" in a way to equate the two. And finally, in John's gospel Jesus speaks of the Spirit as "another Comforter" to come after he leaves them for heaven. In Acts, the work of the Spirit becomes evident. See Holy Spirit.