We demonstrate the existence of a chaotic invariant set of solutions of an idealized model for wind-forced quasi-geostrophic flow over a continental margin with variable topography. The model (originally formulated to investigate mean flow generation by topographic wave drag) has bottom topography that slopes linearly offshore and varies sinusoidally alongshore. The alongshore topographic scales are taken to be short compared to the cross-shelf scale, allowing Hart's (1979) quasi-two-dimensional approximation, and the governing equations reduce to a non-autonomous system of three coupled nonlinear ordinary differential equations. For weak (constant plus time-periodic) forcing and weak friction, we apply a recent extension (Wiggins & Holmes 1987) of the method of Melnikov (1963) to test for the existence of transverse homoclinic orbits in the model. The inviscid unforced equations have two constants of motion, corresponding to energy E and enstrophy M, and reduce to a one-degree-of-freedom Hamiltonian system which, for a range of values of the constant G = E − M, has a pair of homoclinic orbits to a hyperbolic saddle point. Weak forcing and friction cause slow variations in G, but for a range of parameter values one saddle point is shown to persist as a hyperbolic periodic orbit and Melnikov's method may be applied to study the perturbations of the associated homoclinic orbits. In the absence of time-periodic forcing, the hyperbolic periodic orbit reduces to the unstable fixed point that occurs with steady forcing and friction. The method yields analytical expressions for the parameter values for which sets of chaotic solutions exist for sufficiently weak time-dependent forcing and friction. The predictions of the perturbation analysis are verified numerically with computations of Poincaré sections for solutions in the stable and unstable manifolds of the hyperbolic periodic orbit and with computations of solutions for general initial-value problems. In the presence of constant positive wind stress τ0 (equatorward on eastern ocean boundaries), chaotic solutions exist when the ratio of the oscillatory wind stress τ1 to the bottom friction parameter r is above a critical value that depends on τ0/r and the bottom topographic height. The analysis complements a previous study of this model (Samelson & Allen 1987), in which chaotic solutions were observed numerically for weak near-resonant forcing and weak friction.