We study the physics of electron acceleration at collisionless shocks that move through a plasma containing large-scale magnetic fluctuations. We numerically integrate the trajectories of a large number of electrons, which are treated as test particles moving in the time-dependent electric and magnetic fields determined from two-dimensional hybrid simulations (kinetic ions and fluid electron). The large-scale magnetic fluctuations effect the electrons in a number of ways and lead to efficient and rapid energization at the shock front. Since the electrons mainly follow along magnetic lines of force, the large-scale braiding of field lines in space allows the fast-moving electrons to cross the shock front several times, leading to efficient acceleration. Ripples in the shock front occurring at various scales will also contribute to the acceleration by mirroring the electrons. Our calculation shows that this process favors electron acceleration at perpendicular shocks. The current study is also helpful in understanding the injection problem for electron acceleration by collisionless shocks. It is also shown that the spatial distribution of energetic electrons is similar to in situ observations. The process may be important to our understanding of energetic electrons in planetary bow shocks and interplanetary shocks, and explaining herringbone structures seen in some type II solar radio bursts.