By the mechanism of the inspiration of the Holy Spirit - that is the supernatural power of God. The human authors of the Bible wrote under the direct inspiration of the Spirit, writing exactly and precisely what God wanted them to write in their native language. They willed to submit to God and his will was done, so neither the author's will nor God's was violated.
Note that inerrancy applies only to the original manuscripts, not subsequent translations, nor even copies of them.
According to H. C. Thiessen, giving the Evangelical Pentecostal point of view:
Not only is Scripture inspired and authoritative, it is also inerrant and infallible. By this we mean that it is without error in the original manuscripts. It is inerrant in all that it affirms, whether in historical, scientific, moral, or doctrinal matters. Inerrancy extends to all of Scripture and is not limited to certain teachings of Scripture.
-- Lectures in Systematic Theology, Thiessen & Doerksen, William B. Eerdmans, 1979. [Emphasis mine.]
The Catholic position is similar, though worded less concretely, probably to protect the duality of scripture and tradition within that body:
II. Inspiration and Truth of Sacred Scripture
105 God is the author of Sacred Scripture. “The divinely revealed realities, which are contained and presented in the text of Sacred Scripture, have been written down under the inspiration of the Holy Spirit.”
“For Holy Mother Church, relying on the faith of the apostolic age, accepts as sacred and canonical the books of the Old and the New Testaments, whole and entire, with all their parts, on the grounds that, written under the inspiration of the Holy Spirit, they have God as their author and have been handed on as such to the Church herself.”
106 God inspired the human authors of the sacred books. “To compose the sacred books, God chose certain men who, all the while he employed them in this task, made full use of their own faculties and powers so that, though he acted in them and by them, it was as true authors that they consigned to writing whatever he wanted written, and no more.”
107 The inspired books teach the truth. “Since therefore all that the inspired authors or sacred writers affirm should be regarded as affirmed by the Holy Spirit, we must acknowledge that the books of Scripture firmly, faithfully, and without error teach that truth which God, for the sake of our salvation, wished to see confided to the Sacred Scriptures.”
-- Catholic Catechism. [Emphasis original.]
The most salient section being the last bit: "firmly, faithfully, and without error teach that truth which God, for the sake of our salvation, wished to see confided to the Sacred Scriptures".