He captures a key stepping stone to a second term in the White House and extends the state's streak of supporting Democrats to six elections.
No Democrat has won the White House without Pennsylvania in 64 years.
Pennsylvania is a top Electoral College prize, tied with Illinois for the fifth-most votes.
Obama's victory in Pennsylvania was his second straight, beating Republican John McCain in 2008 by 10 percentage points.
Although Pennsylvania is traditionally treated as a battleground state, the candidates nevertheless ignored it until a last-ditch blitz of TV ads and visits by Romney and his Republican allies.