The 26-year-old England player's contract with the Gunners expired at the end of June.
"It feels special. Many people know that I've had a special bond with this club growing up," he said.
"I've got good memories of my childhood supporting West Ham, watching them at Upton Park."
The Hammers are also closing in on the signing of Ukraine forward Andriy Yarmolenko.
A fee of about 20m euros (£17.66m) is understood to have been agreed with Borussia Dortmund.
Wilshere is set to fly to Switzerland to link up with new West Ham manager Manuel Pellegrini's squad at the club's pre-season training camp.
Despite his career being badly affected by injuries, the Hammers are confident Wilshere can make a meaningful contribution to a squad being overhauled by Pellegrini.
West Ham director of football Mario Husillos said: "Manuel and I identified him as a target as soon as we joined the club and we are delighted to have succeeded in securing Jack's signature above a number of other teams."
Wilshere made 197 first-team appearances for Arsenal and was part of the 2014 and 2015 FA Cup-winning sides.
After spending the 2016-17 campaign on loan at fellow Premier League side Bournemouth, he returned to the Gunners and made 38 appearances last season but was not included in Gareth Southgate's England World Cup squad.
Yarmolenko, 28, has scored 35 times in 77 appearances for his country.
He joined Dortmund from Dynamo Kiev in August 2017 but struggled to find his best form in Germany, scoring six goals in 26 appearances.
"They called me not every day but a lot of times telling me to come here," he said.