Zahid Bashir, the premier's press secretary, said two bullets struck the driver's side of the vehicle in a "murder attempt."
State-run Pakistan Television aired footage of Gilani's black Mercedes car with the two impact points clearly visible on the driver's window. The glass was cracked but intact.
"The prime minister is fine, he is back in Islamabad at the PM house," Information Minister Sherry Rehman told Dawn News TV.
The incident adds to the tension in Pakistan at a time when its new civilian government is vowing to crack down on Islamic militants after ousting U.S. ally Pervez Musharraf from the presidency.
It was also the second apparent assassination attempt in quick succession.
Shots were fired last week at a car carrying Lynne Tracy, the top U.S. diplomat in Pakistan's troubled northwest, as she was heading toward her office in the city of Peshawar. No one was hurt.