Ismail Haniya's convoy came under attack as it passed through the Nusseirat refugee camp in central Gaza shortly after his speech, but the Hamas leader was unhurt.
Hamas officials said the attack did not appear to be an assassination attempt, but it came at a time of growing tensions between rival Palestinian factions that have sparked fears of civil war.
An official in Haniya's office said: "The prime minister is alright and he is out of the area which witnessed the gunfire. His car was not attacked."
Islam Shawan, a spokesman for Hamas's armed wing, said that the last car in the motorcade was hit and set alight. There were no reports of injuries.
Abbas has hinted that he might fire the Hamas government after efforts to form a unity cabinet foundered over Hamas's refusal to soften its stance toward Israel.
Haniya said in a speech at a mosque on Friday it would be pointless for Abbas to fire the government, suggesting that any emergency administration the president appointed would not get the ultimate approval of parliament, where Hamas has an absolute majority.
He also said Hamas would reject other measures such as calling early elections.
Haniya said: "All you have here are options that have no aim but to remove Hamas from government. The wheel of history will not go backward.
"All these options will not achieve stability and calm and will not represent a way out of the crisis."
Haniya did not threaten explicit action to oppose Abbas, such as calling Hamas supporters out on to the streets.
Abbas said this week that he would make a decision soon on the fate of the government.
The president has not explicitly identified his options but his aides have said that he might call fresh elections, appoint an emergency cabinet or hold a referendum to let the Palestinian people decide what to do.
A senior Abbas aide told Reuters on Thursday that the president was expected to make his decision several days after the Eid al-Fitr holiday, which marks the end of the Muslim fasting month of Ramadan. Eid this year falls on around October 23.
Palestinians had hoped that a unity government would lead to a lifting of crippling Western sanctions that were imposed on Hamas when it took office in March.