The pivotal Battle of Gettysburg opened on July 1st as 2,500 Union cavalry led by John Buford fought a delaying action against 20,000 Confederates under Henry Heth. Buford, using the high volume of fire provided by the cavalry carbine (12 shots per minute versus 1-2 for a musket) and two ridges northwest of the town, successfully fought a delaying action, allowing time for John Reynold's 1st Corps to arrive and deploy. They were soon joined by Oliver Howard's 11th Corps. But four strong Rebel forces joined Heth. When Robert Rodes' and Jubal Early's divisions attacked from the northeast, turning Howard's flank, the 11th Corps, as they did at Chancellorsville two months earlier, broke and ran. Reynold's had been killed by a sniper and command had passed to Abner Doubleday, who did a commendable job. But with 11th Corps' collapse, 1st Corps' flank was left hanging and Doubleday was forced to withdraw into the town. As the Union troops took possession of Cemetary and Culp's Hills south of the town, General Winfield Hancock, sent by Meade after Reynold's death, took command. Lee provided discretionary orders to Richard Ewell to take Cemetary Hill, but Ewell, citing exhausted troops, declined. It proved to be a missed opportunity that turned the battle.
The second day, July 2nd, saw Union forces deployed in a fish hook-shaped defensive line defined by the two hills in the north with the shank running south along Cemetary Ridge to two round-topped hills in the south. During the day, more Union forces arrived, five corps altogether and were deployed along the top of the ridge. This was the high ground that Buford saw on June 30th, that he predicted would determine the result of the battle. The Confederate battle plan was to attack both flanks, but delays were incurred as James Longstreet waited for more troops to arrive. During this delay, Union General Dan Sickles, a political power from New York City, decided that the assigned position for his 2nd Corps was unsatisfactory. Without telling Meade, Sickles ordered his men off the ridge and down into the valley, anchoring on a field of massive boulders named Devil's Den. By the time Meade found out and ordered Sickles to redeploy, Longstreet had finally commenced his attack. He was able to turn the flank of the 2nd Corps. Union troops held the hills in the north and thanks to timely decisions by Gouvenor Warren, and heroic stands by the 1st Minnesota and 20th Maine, among others, the rebel surge in the south was turned back. Meanwhile, Jeb Stuart, acting on an extraordinarily liberal interpretation of Lee's orders, had embarked on another glory ride, seeking to ride around the Union army as he had done once before. Therefore the job of intelligence collection which cavalry was supposed to be doing was not done, leaving Lee in the dark about enemy forces.
On July 3rd, Lee opened his final attack with a massive artillery barrage that lasted for nearly two hours. The din from the 170 Confederate cannon and the counter-battery fire from Union artillery was said to have been heard as far away as Pittsburgh. However, the barrage failed in it's intent, to drive Union artillery away and blast a hole in the center of the Union line. 12,000 Confederate troops, led by General George Pickett moved out of the tree line and advanced across a mile of open field, bisected by a double fence line along the Emmitsburg Road. The southerner's, keeping tight disciplined lines, marched bravely into a blizzard of shot and shell from Union artillery in front and on either flank, and two corps of infantry ensconced behind a protective stone wall. Despite the bad odds, incredibly the Rebel troops actually pierced the Union line. Hancock's close friend, Confederate General Louis Armistead, was mortally wounded inside the Union line, minutes before Hancock himself was wounded. But Lee had committed all his troops to the attack and had no reserves with which to exploit the breakthrough. Union reserves, ordered into the line, pushed the Confederates back. Lee lost almost 60% of his attacking force. While this fight was ongoing, Jeb Stuart's cavalry, finally back from their ride, attempted a pincer attack towards the back side of the Union position. His troopers were met by a numerically inferior Union cavalry force that, despite their low numbers, ferociously charged and engaged Stuart, resulting in a rare southern defeat. One of the officers leading that Union charge was one George Armstrong Custer. That night, with his army in shambles, Lee made the decision to withdraw southward. Lee's invasion of the North was over.