In April 1844, Spain recognized Chile's independence, and both nations formally established diplomatic relations after the signing of a "Treaty of Peace and Friendship". In March 1866, during the Chincha Islands War, Spain bombarded the Chilean port of Valparaíso in retaliation for Chile's participation in the war and for refusing Spanish ships to dock at Chilean ports.