On July 19, following a series of unsuccessful Union attacks on his flanks, General Early decided to withdraw from his precarious position at Berryville to a more secure position near Strasburg. During the evacuation of the military hospitals and storage depots at Winchester, Union forced under Brig. Gen. William W. Averell won a rare victory over Confederate forces under Maj. Gen.Stephen D. Ramseur at the Battle of Rutherford's Farm. The poor Confederate performance at the battle, as well as a series of small cavalry engagements south of Winchester the following day lead Union commanders George Crook and Horatio Wright to conclude the Confederates were merely fighting a rearguard action and that Early was leaving the valley and heading for Richmond.
With the threat to Washington, D.C., seemingly over, Wright withdrew the VI Corps and XIX Corp from the valley to return to the aid Grant's siege of Petersburg, Virginia on July 20, leaving only the three-division strong Army of the Kanawha in the valley. The following two days were relatively quiet with both armies resting in their camps some 15 miles from each other. On July 23 Confederate cavalry attacked the Union advanced picket line Kernstown, leading to a sharp cavalry skirmish. From prisoners caught in the skirmish Early learned of Wright's departure. In order to continue to be of service to Lee in the valley, Early realized he had to attack the diminished force in front of him to ensure that Grant's force at Petersburg would not be reinforced.
On the morning of July 24 Early marched his army north against Crook. Confederate cavalry encountered its union counterpart south of Kernstown in the morning and heavy skirmishing broke out. Couriers alerted Crook to the attack. Crook still believed Early's infantry had left the Valley and sent only two of his division with cavalry support to meet the attack. In the early afternoon the infantry of both armies had arrived on the field. The Confederate position extended well to each side of the Valley pike south of Kernstown, anchored on each flank on high ground and screened by cavalry. Maj. Gen. John B. Gordon's division formed the Confederate center along the Valley Turnpike. Ramseur's division formed on his left with its flank resting on Sandy Ridge to the west of Kernstown, screened by Col. William "Mudwall" Jackson's cavalry. Brig. Gen. Gabriel Wharton's division, led by Maj. Gen. John C. Breckinridge, formed the Confederate right, with its flank screened by Brig. Gen. John C. Vaughn's cavalry. Early initially concealed his infantry in a woods, sending out his cavalry and skirmish line of sharpshooters to draw the Federals into battle, thus playing into Crook's misconception that he the Confederate infantry had left the Valley.
The Union infantry position remained clustered around the Valley Pike in Kernstown anchored by Col. James A. Mulligan's division on Pritchard's Hill, one of the keys to the Union success at the First Battle of Kernstown in 1862. To his right, Col. Joseph Thouburn's division formed on Sandy Ridge. To his left, future president Rutherford B. Hayes's brigade formed east of the Valley turnpike. Crook dispatched cavalry under Averell to ride around the Confederate right flank and get in its rear. As the two armies skirmishers encountered one another the battle got under way. It soon became apparent to the Federal divisional commanders that they were facing a superior Confederate force which they were hesitant to attack and relayed the information to Crook.
Crook soon became impatient at the lack of his division commanders to attack the Confederate position, and distrusted their report of the Confederate strength. He ordered Mulligan to attack the Confederates with Hayes division in support. At 1 p.m. the Union infantry reluctantly moved out, abandoning Pritchard's Hill. Mulligan's division bitterly held it ground at Opequon Church where its advance was halted by Gordon's men. As Hayes's brigade advanced in support, Breckinridge marched Wharton's division to northeast to a deep ravine that ran perpendicular to the Valley Turnpike. He turned the division into the ravine, which screened his movement from the Federals on the turnpike. As Hayes came up the road past the ravine, Breckinridge ordered a charge and the Confederates assaulted Hayes's exposed flank and sent his division reeling in retreat, taking many casualties.
Thoburn was supposed to support Mulligan's right flank in the attack, but because of the topography of the battlefield, he became separated from Mulligan and saw little action during the battle. Gordon's Confederates exploited the gap in the Union line to get on Mulligan's right and when Hayes' division broke Mulligans found himself caught between two Confederate divisions. Mulligan immediately ordered a withdrawal, and was mortally wounded as he tried to rally his troops and prevent a full rout during the retreat. The Confederate infantry pressed the fleeing Federals all the way back through Winchester and the cavalry kept at their heels well into West Virginia.
Averell's cavalry had attempted to flank the Confederates as ordered but ran headlong into Vaughn's cavalry on the Front Royal Pike. The shock of the unexpected Confederate cavalry attack sent the Federal cavalry racing towards Martinsburg. When the fleeing cavalry encountered the retreating wagon and artillery trains north of Winchester it incited a panic among the Federal teamsters, causing many to abandoned their charges as they got caught up in retreat. Many of the wagons had to be burned to prevent them from falling into Confederate hands. As night fell the Confederate cavalry swept the countryside looking for Federals who had become lost from their units in retreat. Most of the Federals spent the night out in the rain, scattered across countryside, trying to evade capture.
With his army broken, Crook retreated to the Potomac River and crossed near Williamsport, Maryland, on July 26. As a result of this defeat and Early's burning of Chambersburg, Pennsylvania, on July 30, Grant returned the VI and XIX Corps to the Valley and appointed Maj. Gen. Philip Sheridan as commander of Union forces there.