An optimal control problem for a controlled backward stochastic partial differential equation in the abstract evolution form with a Bolza type performance functional is considered. The control domain is not assumed to be convex, and all coefficients of the system are allowed to be random. A variational formula for the functional in a given control process direction is derived, by the Hamiltonian and associated adjoint system. As an application, a global stochastic maximum principle of Pontraygins type for the optimal controls is established.