We propose an implementation of a two-dimensional Z2 lattice gauge theory model on a shallow quantum circuit, involving a number of single and two-qubits gates comparable to what can be achieved with present-day and near-future technologies. The ground state preparation is numerically analyzed on a small lattice with a variational quantum algorithm, which requires a small number of parameters to reach high fidelities and can be efficiently scaled up on larger systems. Despite the reduced size of the lattice we consider, a transition between confined and deconfined regimes can be detected by measuring expectation values of Wilson loop operators or the topological entropy. Moreover, if periodic boundary conditions are implemented, the same optimal solution is transferable among all four different topological sectors, without any need for further optimization on the variational parameters. Our work shows that variational quantum algorithms provide a useful technique to be added in the growing toolbox for digital simulations of lattice gauge theories.