A test of CP invariance in Higgs boson production via vector-boson fusion using the method of the Optimal Observable is presented. The analysis exploits the decay mode of the Higgs boson into a pair of τ leptons and is based on 20.3 fb−1 of proton–proton collision data at √s = 8 TeV collected by the ATLAS experiment at the LHC. Contributions from CP-violating interactions between the Higgs boson and electroweak gauge bosons are described in an effective field theory framework, in which the strength of CP violation is governed by a single parameter d~. The mean values and distributions of CP-odd observables agree with the expectation in the Standard Model and show no sign of CP violation. The CP-mixing parameter d~ is constrained to the interval (−0.11,0.05) at 68% confidence level, consistent with the Standard Model expectation of d~=0 .