At the battle of Guilford Courthouse, Major-General Nathanael Greene used an elaborate defense-in-depth to wear down the advancing British infantry. He hoped they would be primed for defeat by the time they reached the Continentals posted on the the third and final line. However, a number of things had not gone as planned. The North Carolina militia retreated without orders on the first line (Part 4). So too did part of the Virginia militia on the second line (Part 6). Also, Lieutenant-Colonel Henry Lee’s flank corps had become separated from rest of the army (Part 8). Finally, on the third line, the 2nd Maryland regiment gave cursory resistance to the British 2nd Battalion of Guards, then broke and fled (Part 10). Greene later wrote:
[the Guards had] turned our left flank, got into the rear of the Virginia brigade, and appearing to be gaining on our right, which would have encircled the whole of the continental troops, I thought it was most advisable to order a retreat. 
There is some unwitting exaggeration in this description. The Guards had gained the rear of the American line, but probably they had not yet advanced as far as the Virginia regiments. The Guards were also much too few in number to encircle “the whole of the continental troops”. Nevertheless, the sudden collapse of his left flank may have appeared to presage the total defeat of his army. Greene's orders to retreat no doubt seemed prudent.
However, the Continental units nearest the 2nd Guards had already chosen to take matters into their own hands.
Lieutenant-Colonel John Eager Howard of the 1st Maryland recalled:
[M]y station being on the left of the first regiment, and next the cleared ground, Captain Gibson, deputy adjutant-general, rode to me, and informed me that a party of the enemy, inferior in number to us, were pushing through the cleared ground and into our rear, and that if we would face about and charge them, we might take them. We had been for some time engaged with a part of Webster's brigade, though not hard pressed, and at that moment their fire had slackened. I rode to [Colonel John] Gunby and gave him the information. He did not hesitate to order the regiment to face about, and we were immediately engaged with the guards. 
Also nearby was Lieutenant-Colonel William Washington’s cavalry, which consisted of the 1st and 3rd Light Dragoons, and additional troops raised recently in North Carolina and Virginia.
Lieutenant Philemon Holcombe, who served under Washington, recalled:
Colo[nel] Washington’s command was in view of the conflicting armies and were spectators of the bloody scene for several hours. The Carolina Militia had given way, and the second and third lines of the american army were hard pressed, and the British columns were passing to the rear of the american line, flushed with victory, marching rapidly and in some confusion. 
Coolly appraising the situation, Washington did not hesitate to act. In Holcombe’s words, “the brave and gallant William Washington ordered a charge upon their columns”.
The 2nd Battalion of Guards (at center) is simultaneously attacked by the 1st Maryland Regiment (shown here with a blue regimental flag), and Washington's cavalry (the mounted men at left). (Click to enlarge).
Another view of the above; North Carolina militiamen look on as Washington's cavalry charges.
1. Greene's account of the battle (among others) can be found in this compendium.
2. Howard is quoted in James Herring and James Barton Longacre (1835). The national portrait gallery of distinguished Americans, Vol. 2.