The Great Heathen army wasn't some great, unstoppable force. In fact, they were very nearly defeated by the Northumbrians outside York shortly after their initial arrival in England. The Anglo-Saxon Chronicle and Asser's Vita Ælfredi charts a long series of battles throughout the late 860s and early 870s and Wessex continually fights the Vikings to a standstill. In 871 alone, Æthelred and Alfred fight something like 11 separate battles against Viking forces, not counting the myriad of smaller actions fought by local forces against Viking raiding parties. Asser illustrates the extent to which this constant attrition is bleeding Wessex dry in its need to always have men at war.
What actually turns the tide decisively towards Alfred is the combined reform of the defensive network and the fyrd system. Based around fortified sites called burhs, Alfred's network is designed to comprehensively curtail the Viking ability to manoeuvre quickly, which forms the basis of much of their strategy. The foundation of the network are the burhs, fortified garrison sites situated at prominent river crossings, road junctions, bridges, landing sites, etc. These are combined with a whole series of regional strongholds, all connected by a series of communication sites. This system means that a constant watch is maintained along the frontier, and Viking forces are denied strategic mobility, while Anglo-Saxon fyrd garrisons are able to utilise the roads and rivers to respond rapidly to any threats, as well as to rapidly join up with other English forces to force the Vikings into battle at sites of the English choosing and with numerical superiority wherever possible.
The fyrd system itself appears to be an overhaul of a pre-existing system. The system provides for the closest thing to a semi-professional standing army, with a rotational system providing a constant garrison presence at burghal sites meaning that response times are much quicker and there is the possibility to provide at least a basic level of formational training to English forces. A document known as the Burghal Hidage shows how land in each county was assigned to provide supplies for the garrison, and how large the garrisons of each site were.
A good illustration of the effectiveness of the system comes in 878, when Wessex is supposedly over-run by the Vikings. At the same time as Alfred is attacked at Chippenham, a large Viking raid attacks Exeter, but is destroyed by the city's garrison, and Alfred's Easter counterattack is bolstered by the garrison forces of Somerset, Wiltshire, Dorset and Hampshire, which suggests that those areas remained unconquered. Other prominent victories at least in part due to the burghal system happen in 893 and 911.