Using the polynomial method of Dvir [On the size of Kakeya sets in finite fields. Preprint], we establish optimal estimates for Kakeya sets and Kakeya maximal functions associated to algebraic varieties W over finite fields F. For instance, given an (n−1)-dimensional projective variety W⊂¶n(F), we establish the Kakeya maximal estimate for all functions f:Fn→R and d≥1, where for each w∈W, the supremum is over all irreducible algebraic curves in Fn of degree at most d that pass through w but do not lie in W, and with Cn,W,d depending only on n,d and the degree of W; the special case when W is the hyperplane at infinity in particular establishes the Kakeya maximal function conjecture in finite fields, which in turn strengthens the results of Dvir.