Although the germ of the idea might've appeared in Koszul's earlier work on the cohomology of Lie algebras and homogeneous spaces, it seems that the first full-fledged appearance of the Koszul complex/resolution is in Koszul, *Sur un type d'algèbres différentielles en rapport avec la transgression*, Colloque de topologie (espaces fibrés), Bruxelles (1950), 73–81. The primary motivation there is topological/geometric (cohomology of fiber bundles), but Koszul does give fairly abstract algebraic results and definitions. Specifically, consider a principal $G$-bundle $p\colon E\to B$, where $G$ is a compact connected Lie group. Write $x_1,\ldots,x_l$ for the primitive generators of $H^\ast(G)$, so that $H^\ast(G)=\bigwedge^l_{i=1} x_i$. Then there are $G$-invariant differential forms $\{\omega_i\}$ on $E$ whose restrictions $\{\xi_i\}$ to a fiber $G$ are bi-invariant forms that represent the classes $\{x_i\}$ and such that $d\xi_i$ is the image under $p^\ast$ of some form $c_i$ on the base $B$. The exterior algebra $\Omega^\ast(B)$ of $B$ may be viewed as a module over the polynomial ring $A=\mathbb R[c_1,\ldots,c_l]$. Koszul is led to the "Koszul complex"
$$ {\textstyle \bigwedge_{i=1}^l} x_i \otimes \Omega^\ast(B) $$
(with the appropriate differential) through topological considerations: he notes that in certain cases (for nice enough $B$), one can replace $\Omega^\ast(B)$ above with $H^\ast(B)$ and then the resulting complex $\bigwedge x_i \otimes H^\ast(B)= H^\ast(G) \otimes H^\ast(B)$ computes the cohomology of $E$.

Koszul takes a look at the general properties of "Koszul complexes" of the form $E \otimes M$ where $E=\bigwedge_{i=1}^l x_i$ and $M$ is a module over $A=k[x_1,\ldots,x_l]$, and calls the resulting cohomology $H^\ast(M)$ the cohomology of the $A$-module $M$. He proceeds to use this machinery to give a generalization of Hilbert's syzygy theorem. This is, e.g., the context in which the Koszul complex arises in Cartan & Eilenberg's book on homological algebra (see Ch. VIII, sections 4 and 6)---and this is probably (?) the first textbook appearance of the construction.

See also A. Haefliger, *Des espaces homogènes à la résolution de Koszul*, Ann. Inst. Fourier **37**(4) (1987), 5–13, for some interesting historical commentary on Koszul's work.