TEL AVIV—Mark Shindel and his Israeli friends arrived at the music festival about 1 a.m. and drank and danced until sunrise.

Shindel’s high-school pal Orel Dorf shouted over the music how great it was to share so many happy times. Last year, they traveled to Mexico and Miami, where they had rented Jet Skis and partied at dance clubs on a night that ended with takeout burgers at 6 a.m.

Shindel and his friends, all in their early 20s, belonged to a generation raised with seemingly endless opportunities, free of the existential fears of parents and grandparents traumatized by the Holocaust and the threat of annihilation by Arab neighbors.

They kept a child’s faith in Israel’s military and intelligence prowess, rejoicing to trance music at an all-night festival a few miles from territory ruled by Hamas, a group out to destroy them and their country.

The sun was coming up around 6:30 a.m. when rockets from Gaza fizzed through the sky. Festival organizers cut the music and sounded a siren. Shindel and his friends piled into their car and joined a long line stretching to the exits.

Israelis, especially in the southern part of the country, are accustomed to Hamas rockets blown from the sky by the military’s Iron Dome antimissile system.

The friends were no different. They grew up in a Tel Aviv suburb and entered adulthood during an era of prosperity. One was a disc jockey, playing festivals in Europe. Another dreamed of working for a tech startup. Shindel, who was preparing to begin his university studies, wanted to be a civil engineer. Dorf started a digital-marketing firm.

Shindel talked and joked through the car window with a group of girls who gave him fruit and bottles of water. He got out of the car and began giving away the water and fruit toothers waiting in line.

“Water, water,” he called out in a video that caught a moment before everything changed. Soon after, people started running and clambering out of cars like a scene from a horror movie, trying to flee something terrible coming their way.

Suburbia

Shindel was born in 2000 and grew up in Kfar Yona, a commuter town about 30 minutes from Tel Aviv. Housing was less expensive, and families that could afford only an apartment in the city could have a house in Kfar Yona.

Shindel’s mother, Julia, had emigrated from Estonia and later met Igor Shindel, who was from Ukraine and had two boys from a previous marriage. He held a computer-science degree and worked in the early days of Israel’s tech industry.

Gal Kisus, 24 years old, said he met Shindel in the third grade, but they only became close in high school. They had summer jobs as teenagers, waiting tables at an event venue. One night, they smuggled out a leftover bottle of wine and spent hours talking and drinking.

During the Passover holiday one year, Shindel went to Kisus’s house and asked Kisus’s mother if he could help with anything. She said she wanted the house painted. Going along with the joke, Shindel picked up a brush and got started painting rooms.

Shindel and his friends reflected the mix of Jewish backgrounds in Israel some 75 years after its birth. His family were émigrés of the former Soviet Union. His friends were of European and Middle Eastern descent. One had lived in Canada as a child. Like Shindel, most learned English.

When Shindel was 17, his older stepbrother, Adam Shindel, died by suicide, a tragedy in an otherwise easygoing life. To memorialize Adam, he and his father got tattoos with their initials, Adam’s and Guy Shindel’s, his other stepbrother.

“It didn’t matter how hard he worked and studied, he had to finish the week by going out with friends,” said Ashley Hasson, 22, who dated Shindel in high school for three years

After high school, Shindel and his friends joined the military—mandatory service for most Jewish Israelis. Men usually serve for 32 months and women for 24 months. Shindel had wanted to be in a combat unit, his mother said, but after Adam’s death, he instead worked as a gunsmith, repairing and maintaining military firearms. Dorf joined a military police unit based at Tel Aviv’s Ben Gurion Airport. Kisus fixed tanks.

Shindel and Kisus served together in basic training, where recruits practice drills and learn to fire weapons. One night, when everyone was asleep in the barracks, they drew on the foreheads of comrades and put shaving cream on their palms. One soldier woke up shouting, Kisus said. Shindel couldn’t stop laughing.

The friends returned to civilian life around 2021 and, like most young Israelis, saved money to travel abroad before starting work or entering a university.

“This generation went to school, went to the army, finished the army, went to university, traveled abroad. Just lived,” said Orly Fox, Shindel’s former high-school homeroom teacher. “They lived their lives.”

Clubs and cafes

Shindel’s generation grew up in a golden age for Israel’s economy, driven by Tel Aviv’s emergence as a tech hub. National output grew to $475 billion in 2022 from $162 billion in 2000, according to the Organization for Economic Cooperation and Development.Foreign direct investment into Israel went to roughly $28 billion last year from $7 billion in 2000, United Nations data show.

Skyscrapers reshaped Tel Aviv’s profile. It became a cosmopolitan city, drawing Jewish people from around the world to chic cafes and restaurants run by celebrity chefs and offering well-paid jobs at tech companies.

Shindel went to popular dance clubs in Tel Aviv with his friends and flirted with confidence. “If there were girls in the area, and you didn’t hit on them first, Mark would,” said Aylon Herson, one of Shindel’s high-school friends.

New tech millionaires spent freely. Home prices in Tel Aviv tripled in the two decades that ended in 2022, the highest growth rate among 25 major cities worldwide, according to an analysis this year by Swiss bank UBS.

Karnit Flug, 68, who served as the governor of the Bank of Israel from 2013 to 2018, said that by any measure—wages, employment or per capita GDP—Israel had prospered over the past 15 years. After brief conflicts with Hamas in 2012, 2014 and 2021, she said, the economy bounced back quickly.

When Flug was a child growing up in Jerusalem, people went door-to-door with ice for families without a refrigerator. Households waited two years for a telephone line in the late 1970s or shared a line with another family.

Flug went to study in New York in 1980, and she found her cousin had her own phone. “That seemed to exemplify the vast difference in the level of infrastructure between Israel and New York at the time,” she said.

For Flug and earlier generations, the focus on survival had for decades left Israel’s economy insular and slow to develop.

The country lost nearly 800 soldiers in the 1967 war, when Israeli forces took control of the Jordanian-controlled West Bank, the Gaza strip and the Sinai Peninsula from Egypt, as well as the Golan Heights, then in Syria. In 1973, Arab armies carried out a surprise attack, setting off a war that killed 2,700 Israeli soldiers. The intelligence failure by the Israeli military left the country scarred.

In the 1980s, Israel fought a war in Lebanon to expel Palestinian leadership from the country, a conflict that extended into a 15-year occupation of southern Lebanon and initiated along fight with Hezbollah.

Efforts to agree on a two-state solution between Israelis and Palestinians in the 1990s were marred by Hamas bombings. After the Palestinian uprising of the early 2000s, known as the second intifada, the government walled off Palestinians, allowing Israelis to largely ignore the longstanding conflict.

With less experience of war, Israelis born in the 21st century were instead immersed in opportunities to make money and have fun.

Shindel and his friends had talked for months about October’s Tribe of Nova, a spinoff of a Brazilian trance festival.

In hiding

After the sun rose on Oct. 7, and sirens replaced the festival music, the friends sat in their car, waiting to exit. When the attackers came into sight, Dorf shouted for Shindel and two others, Shahaf Zavot and Ofir Shalom, to get out and run.

Zavot saw two militants on a motorcycle headed toward them. The four friends joined others running down to a dry stream bed in a ravine, partly concealed by trees. Bullets whistled past. They heard screams from the parking lot above.

Dorf’s phone was dead, and he texted his mother on Shindel’s.

“Everything’s alright. I’m going back home,” he wrote. “Don’t be afraid.”

Shindel sent a message to his own mother: “Everything is ok. I’m fine.”

Minutes passed. Shindel looked at Dorf and extended his hand to shake, telling his friend they would get through it together.

Militants started shooting toward them, and Dorf and Zavot jumped into bushes to hide. Shindel and Shalom ran along the stream bed about 400 yards and stopped to look at a map on their phone. Shalom’s father called and asked his son to share their location so he could try to send help.

Shindel yelled that there was a militant ahead with a rifle, and the two friends turned and ran. Shalom heard Shindel shout in pain and saw him grabbing the back of his leg.

A bullet skinned Shalom’s elbow, drawing blood. He bolted out of the ravine toward a parked car and squeezed in with eight strangers, four in front and four in the back seat. The driver sped from the festival grounds to the highway.

Militants on the road fired at the car. Bullets hit the driver, but he managed to get the group to the Re’im military base a few miles away. Soldiers there were in a firefight with a larger group of attackers. Shalom, who had been an officer during his military service, was handed a gun and joined Arab Bedouin soldiers and members of an elite air force unit defending the base.

He fought in the battle for a couple of hours before reinforcements arrived, and he joined other festivalgoers waiting in a building at the base. The battle outside continued until the militants were killed that night. The driver of the car he had escaped in and a fellow passenger died from their wounds, he said.

Back at the festival grounds, Dorf had stayed hidden in a bush, listening to rifle fire and smelling burning cars. He heard a gunshot followed by a car horn blaring and thought a driver’s dead body must be pressing against the steering wheel. He wondered if he was next to die.

Nearby, Zavot was hiding in a bush so small his legs stuck out. He wore pants a color close to the shrub’s and remained unnoticed.

A quiet fell in late afternoon, and Dorf heard voices speaking Hebrew. A soldier yelled that anyone hiding should come out with their hands up. He escorted Dorf and others away from the festival grounds, telling them to keep their eyes down. Dorf took a quick look and saw blood-splattered cars and charred bodies.

Later, he saw Shahaf, and they embraced. Dorf asked if he knew where Shindel and Shalom were.

For three days, Dorf and his friends searched for Shindel in hospitals. They spoke with festival goers and soldiers who responded to the attack. Shindel’s mother and her friends posted photos of him on social media, including images of the tattoos that memorialized his stepbrother.

‘Never imagined’

At his funeral, Mark Shindel was covered by a sheet. Not even his parents were allowed to see the body. Shindel’s mother had provided DNA to help authorities identify him. He was 23.

“I just don’t get that you’re not here with us,” said Dorf, 23, in his eulogy. He had been afraid to look at Shindel’s mother. But she told him days before the funeral that she wasn’t angry and didn’t blame him, he said.

“I never imagined a reality where I would stand here and speak about you in the past tense,” said Herson, Shindel’s high-school friend, during his eulogy.

While heading to the funeral, Shalom couldn’t believe his friend was gone. He thought about how they had just been dancing and laughing together. He said his friend’s death felt real only after seeing Shindel’s covered body.

At the burial, the friends walked silently to Shindel’s plot and used shovels to help cover his body with dirt.

Some of them are now in therapy. Some struggle with sleep. Others are back in the army, in a war with Hamas. They belong to a generation now wrestling with deep questions about their future and the future of their country.

“I never felt the enemy,” Dorf said. “It was the first time for me. I saw it with my eyes, and I understood what it is to be Jewish, and what it is to be Israeli.”

Write to Rory Jones at Rory.Jones@wsj.com