Maybe there are some perceptions of the analogy in the work of Gauss, but for certain the close relation between Z and F[x] where F is a finite field was established in 1857 in a paper of Dedekind, which went so far as to formulate a version of the quadratic reciprocity law when F has odd characteristic.
In 1919, Kornblum used L-functions on F[x] to prove an analogue of Dirichlet's theorem (for irreducible polynomials in arithmetic progression). While those L-functions could after the fact be viewed as L-functions of characters on a function field, Kornblum worked with characters on (F[x]/(f))*, much as one can prove Dirichlet's theorem without any hint that there are number fields (inside cyclotomic extensions) lying in the background.
In 1921, Artin's thesis on quadratic function fields laid out probably for the first time how close number fields and function fields over finite fields (not only Q and rational function fields) are. For example, he defined concepts of real and imaginary quadratic function fields, showed units in the "real" case could be found by something like a continued fraction algorithm (if I'm not mistaken) and he computed examples of their zeta-functions and could verify in those examples that the Riemann hypothesis was true.
A simple and convenient place to find a treatment of this history is Peter Roquette's website
https://www.mathi.uni-heidelberg.de/~roquette/manu.html
and a direct link to his paper laying out this analogy is the paper
https://www.mathi.uni-heidelberg.de/~roquette/rv.pdf.
I also recommend the first chapter of A. D. Thomas' "Zeta-Functions: An Introduction to Algebraic Geometry" for a careful explanation of what Artin did in his thesis, particularly the confusion over affine vs. projective notions (which weren't really cleared up until the work of F. K. Schmidt on the zeta-function a few years after Artin's thesis).
In addition to the work on this analogy between number fields and function fields over finite fields, you shouldn't forget about the analogy between number fields and function fields over the complex numbers. In 1882, Dedekind and Weber developed the theory of Riemann surfaces purely algebraically, using ideas from algebraic number theory. They went so far as to say their work applied not just to function fields over C, but over any algebraically closed field of characteristic 0, such as the field of algebraic numbers.