JERUSALEM (AP) — Israel launched its largest offensive in the Gaza Strip in nearly two years, carrying out a blistering aerial assault Tuesday on scores of targets and killing 19 people in what officials called an open-ended operation aimed at ending weeks of heavy rocket fire. As Gaza militants unleashed salvos on Jerusalem and Tel Aviv, Israel mobilized forces along the border for a possible ground invasion.
The offensive set off the heaviest fighting between Israel and the Islamic militant group Hamas since an eight-day battle in November 2012. The militants fired about 160 rockets at Israel, including two intercepted over Tel Aviv, while Israel said it attacked more than 150 sites across Gaza.
Palestinian medics reported at least 19 dead, including six killed in an airstrike that flattened an apartment building in southern Gaza and set off widespread panic.
In a nationally televised statement, Prime Minister Benjamin Netanyahu said continued rocket attacks on Israeli communities would not be tolerated.
‘‘Therefore I have ordered the military to significantly broaden its operation against Hamas terrorists and against the other terrorist groups inside Gaza,’’ he said. ‘‘I call on you to display patience because this operation could take time.’’
Israel and Hamas are bitter enemies that have engaged in numerous rounds of fighting over the years. But until recently, they had been observing a truce that ended the previous hostilities in 2012.
Tensions have been rising since Palestinian militants kidnapped three Israeli teenagers in the West Bank on June 12. Accusing Hamas of being behind the abductions, Israel launched a crackdown on the group’s members in the West Bank and arrested hundreds of people. Hamas, which controls Gaza, responded by stepping up rocket fire.
The situation deteriorated last week after the bodies of the Israeli youths were found, and a Palestinian teenager in Jerusalem was abducted and burned to death in what Palestinians believe was a revenge attack. Six Jewish Israelis have been arrested in the killing, and the rocket fire from Gaza has increased in recent days.
The fighting raged throughout the day. In its fiercest attack, an airstrike flattened the home of a Hamas militant in the southern Gaza town of Khan Younis, reducing the concrete structure into a smoldering pile of rubble.
Panicked residents fled, screaming ‘‘God is great.’’ Some had bloody faces, and crying mothers held small children as they ran away. Screaming Palestinians took away motionless bodies. Palestinian medical officials said six people, including two children, were killed.
Late Tuesday, the normally bustling streets of Gaza City were deserted. Fearing an Israeli ground operation, many residents from areas near the border moved to stay with relatives living deeper inside Gaza.
In southern Israel, hundreds of thousands of citizens were ordered to stay close to home because of the rockets. Israeli streets were also quieter in Tel Aviv and Jerusalem after attempted rocket strikes set off air-raid sirens in Israel’s two largest cities. The Jerusalem municipality said it was opening special bomb shelters.
Militants twice fired rockets at Tel Aviv, Israel’s commercial capital, sending people scurrying for cover. Both projectiles were intercepted by the ‘‘Iron Dome’’ rocket defense system. The second interception was shown on live TV, as a winding plume of smoke followed the interceptor into the black skies, culminating with a flash.
Late Tuesday, Hamas said it fired a salvo of four rockets toward Jerusalem, and two distant booms could be heard from the city’s center. One rocket landed in the Jerusalem area, officials said, and police said there were no injuries.
The army was also checking reports that rockets had flown north of Tel Aviv — which would mark the deepest strikes every carried out by Hamas.
In other violence, the Israeli military said it foiled an attempt by Gaza militants to infiltrate a military base in southern Israel by sea. Lt. Col. Peter Lerner, a military spokesman, said four attackers made it to shore and attacked the base with grenades and automatic rifles before they were killed. An Israeli soldier was slightly wounded.
As Israel built up forces along the border, the government authorized the army to activate up to 40,000 reservists. The army said that about 1,000 soldiers were immediately activated, in addition to an earlier group of 1,500 reservists called into action.
‘‘If we need to go inside in a ground operation, then we will do it. These things are on the table. These options exist. We will not stop anything until the rocket firing ends,’’ said Yitzhak Aharonovitch, the minister for internal security and a member of Netanyahu’s inner Security Cabinet. Israel’s last ground offensive was in 2009.
Asked by Channel 2 TV if there were any efforts underway to reach a cease-fire, he said: ‘‘Not now.’’
The US State Department condemned the rocket fire on Israeli civilians, defended Israel’s right to defend itself, and said it hoped Israel’s ‘‘strong message’’ would deter further attacks. ‘‘But certainly, our preference is to de-escalate the situation on the ground,’’ spokeswoman Jen Psaki said.
Israel and Hamas, which is sworn to the destruction of the Jewish state, agreed to an Egyptian-brokered cease-fire that ended the last round of fighting in late 2012.
In Gaza, Abu Obeida, a masked spokesman for Hamas’ military wing, accused Israel of violating that agreement and demanded that it halt its airstrikes, its recent crackdown in the West Bank and its opposition to a recent Palestinian unity government that is backed by Hamas.
‘‘In the face of this aggression, we affirm that the Zionist enemy should not dream of calm and stability,’’ he said.
Hamas, however, is far weaker than in 2012. At the time, Egypt was governed by the Muslim Brotherhood, Hamas’ close ally. Following a military coup in 2013, Egypt’s new government is hostile to Hamas and has closed a network of smuggling tunnels that was the group’s economic lifeline.
Hamas seized control of Gaza in 2007 from the rival forces of President Mahmoud Abbas. But facing international isolation and an economic crisis, Hamas last month agreed to back a new unity government with Abbas.
Abbas, however, has little real influence over Gaza and Hamas, with an arsenal of thousands of rockets, remains the dominant power there. Smaller and more radical forces than Hamas are also involved in rocket fire from Gaza.
Tuesday’s escalation drew condemnations and calls for restraint from around the world.
UN Secretary-General Ban Ki-moon condemned the indiscriminate multiple rocket attacks on Israel from Gaza and demanded an immediate halt to the attacks, UN spokesman Stephane Dujarric said.
Arab League Chief Nabil Elaraby called for an emergency session of the UN Security Council to take necessary measures to stop the violence.
British Foreign Secretary William Hague condemned the attacks and urged calm. ‘‘The people of Israel have the right to live without constant fear for their security; the people of Gaza also have the right to live in peace,’’ he said.
___Jobain reported from Gaza City, Gaza Strip. Ian Deitch contributed reporting from Jerusalem.