Liouvillian functions are functions that are built up from rational functions using exponentiation, integration, and algebraic functions. We show that if a system of differential equations has a generic solution that satisfies a liouvillian relation, that is, there is a liouvillian function of several variables vanishing on the curve defined by this solution, then the system has a liouvillian first integral, that is a nonconstant liouvillian function that is constant on solution curves in some nonempty open set. We can refine this result in special cases to show that the first integral must be of a very special form. For example, we can show that if the system
d
x
/
d
z
=
P
(
x
,
y
)
dx/dz = P(x,y)
,
d
y
/
d
z
=
Q
(
x
,
y
)
dy/dz = Q(x,y)
has a solution
(
x
(
z
)
,
y
(
z
)
)
(x(z),y(z))
satisfying a liouvillian relation then either
x
(
z
)
x(z)
and
y
(
z
)
y(z)
are algebraically dependent or the system has a liouvillian first integral of the form
F
(
x
,
y
)
=
∫
R
Q
d
x
−
R
P
d
y
F(x,y) = \smallint RQ\,dx - RP\,dy
where
R
=
exp
(
∫
U
d
x
+
V
d
y
)
R = \exp (\smallint U\,dx + V\,dy)
and
U
U
and
V
V
rational functions of
x
x
and
y
y
. We can also reprove an old result of Ritt stating that a second order linear differential equation has a nonconstant solution satisfying a liouvillian relation if and only if all of its solutions are liouvillian.