The Army of the Northern Virginia moved into Maryland September 4, 1862. They wanted to invade because they believed that since they had won every major battle that if they took over most of Maryland they could surround the Capital and therefore get the British support and crush the Union once and for all.
The Army of the Potomac was marching back from their bitter defeat at the second battle of Bull Run. When word came to the soldiers that McClellan was taking command again they cheered up and McClellan ordered them westward toward Lee in blind pursuit.
On September 13, a regiment arrived at a campsite the Confederates had camped out at before and found this secret article "Special Orders No. 191". These were Robert E. Lee's battle plans. Lee was planning to send part of his army to capture Harper's Ferry and he was going to have part of his army go into Pennsylvania. With the third part, he was going to follow up the invasion into Pennsylvania. The last part of his army was to defend their rear.
McClellan thought he couldn't defeat the Confederates because he thought the Confederates had twice as many men as he had. He delayed one day to make sure his battle plans were perfect. The next day he was delayed because Hill, who was defending Lee's rear, put up a fight at South Mountain.
In the meantime, Lee found out McClellan had his plans and he changed his plans and told his army to concentrate their troops at Antietam. They could retreat over the Potomac if needed. They could defend themselves very well because it was naturally a good battlefield because of lots of hills, gullies, and fields.
McClellan still thinking that the Confederates had twice as many men as he did, waited yet another day. That gave Stonewall Jackson enough time to get his men from Harper's Ferry
On the morning of September 16, Hooker and Mansfield attacked Lee's left flank and almost broke through. Then at noon, General Sumner was ordered to advance. Porter started following a road into a weak point in the middle of Longstreet's (CSA) line. Then Burnside (USA) advanced across Burnside's bridge while a detachment of three Union brigades came around the Confederate's flank. The Union put D. R. Jones' men on the run. Then A. P. Hill (CSA) arrived from Harper's Ferry, where he had been securing the supplies that Jackson had captured. That evening Hill turned Burnside's 9th corps around into a routed retreat.
The battle of Antietam was a draw. It was the bloodiest one-day battle of the war. The next morning Lee withdrew from Maryland and the Union did not press their advantage, which led to McClellan's dismissal. One corps was ordered to pursue, but was beaten back at Shepherdstown.