The pair broke away in a twisting finishing circuit on Mairena del Aljarafe's narrow streets before Stybar outduelled his Belgian rival.
German Robert Wagner was third in the 205.9-km leg from Almendralejo.
Following the last relatively flat stage before three days of mountain climbing, Italy's Vincenzo Nibali continues to lead overall with a three-second advantage over American Chris Horner.
Irishman Nicolas Roche is eight seconds off the pace in third.
Stybar, a former double world cyclo-cross champion, said beating Gilbert had been "really difficult".
"I didn't launch a perfect sprint but I still won. Whether you win by one centimetre or one millimetre, that's the most important thing," the Omega Pharma-Quick Step rider told reporters.
Stybar said team mate and world time trial champion Tony Martin of Germany, who lost Thursday's stage in the last seconds following a 175-km solo breakaway, had inspired him.
"Tony so nearly made it, he could have been a legend, and even if he lost, sitting round the dinner table last night, we all felt sad he hadn't won but motivated too," added the Czech.
Stybar was adamant his fourth victory of 2013 and first Grand Tour stage win could not make up for the agony he felt after the Paris-Roubaix classic this year when a collision with a spectator 15-km from the finish wrecked his chances of a top-three result.
"Paris-Roubaix is in April next year," he said, "and that's where I'll get my revenge".
Stybar was among several riders who criticised Friday's finish for being too risky.
"With so many sharp turns and cobblestones and 200 riders all going at full speed, it was dangerous," he explained.
One top contender, Ireland's Dan Martin, crashed in the last 10-km when he hit a hole in the road. A winner of a Tour de France stage in the Pyrenees this year and the Liege-Bastogne-Liege classic in April, Martin was taken to hospital for a check-up on injuries to his right side after completing the course in 116th place.
After three flatter stages, the race returns to hillier terrain on Saturday with a summit finish on the 14-km Altas de Penas Blancas climb in southern Spain.
1. Zdenek Stybar (Czech Republic / Omega Pharma - Quick-Step) 4:51:27"
2. Philippe Gilbert (Belgium / BMC Racing) ST
3. Robert Wagner (Germany / Belkin) +1"
4. Adrien Petit (France / Cofidis)
5. Juan Antonio Flecha (Spain / Vacansoleil)
6. Andrew Fenn (Britain / Omega Pharma - Quick-Step)
7. Edvald Boasson Hagen (Norway / Team Sky)
8. Danilo Wyss (Switzerland / BMC Racing)
9. Klaas Lodewyck (Belgium / BMC Racing)
10. Reinardt Janse Van Rensburg (South Africa / Argos)
1. Vincenzo Nibali (Italy / Astana) 27:29:35"
2. Chris Horner (U.S. / RadioShack) +3"
3. Nicolas Roche (Ireland / Saxo - Tinkoff) +8"
4. Haimar Zubeldia (Spain / RadioShack) +16"
5. Alejandro Valverde (Spain / Movistar) +21"
6. Robert Kiserlovski (Croatia / RadioShack) +26"
7. Rigoberto Uran (Colombia / Team Sky) +28
. Daniel Moreno (Spain / Katusha) +31"
9. Rafal Majka (Poland / Saxo - Tinkoff) +38"
10. Roman Kreuziger (Czech Republic / Saxo - Tinkoff) +42"